Skip to content

Flattening K<M, Fin<T>> where M : Fallible<M> #1424

Answered by louthy
glendonjklassen asked this question in Q&A
Discussion options

You must be logged in to vote

Flatten is monadic, not fallible, so there's no automatic way of flattening two different monad-types.

But, because Fin supports explicit casts to Error (and the when predicate has already tested that the Fin is in a Fail state), you should be able to just cast the k to Error

public static K<M, string> sendGridApiKey =>
    from k in configIO.Map(t => t.SendGridApiKey)
    from _ in when(k.IsFail, error<M>((Error)k)
    select (string)k;

There's potentially a way to do a natural-transformation between K<Fin, A> -> K<M, A> when M is Fallible, but right now none of the interfaces support that (although I am adding natural-transformations soon).

By the way, I'd be slightly wary of going all …

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@glendonjklassen
Comment options

@glendonjklassen
Comment options

@louthy
Comment options

@glendonjklassen
Comment options

Answer selected by glendonjklassen
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants