Skip to content

Question: unwrapping nested monad in Eff/Aff #1251

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

You must be logged in to vote

The way that works for all nested monads is this:

var mox = SuccessEff(Some(100));
var moy = SuccessEff(Some(200));

var mr = from ox in mox             // Extract the Some(100)
         from oy in moy             // Extract the Some(200)
         let rs = from x in ox      // Extract the 100
                  from y in oy      // Extract the 200
                  select x + y      // Repackage as Some(300)
         select rs;                 // Repackage as Eff(Some(300))

Because each LINQ block can only work with one monad at a time, you must extract the inner monads and the use them in a LINQ sub-block.

I've read about tranformer types and checked Transformers package, but didn't find…

Replies: 2 comments 7 replies

Comment options

You must be logged in to vote
3 replies
@louthy
Comment options

@aloslider
Comment options

@louthy
Comment options

Answer selected by aloslider
Comment options

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

@Legys
Comment options

@louthy
Comment options

@Legys
Comment options

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