scala - what is the scalaz filterM method? -


this scalaz tutorial provides example of using filterm method, not explain it.

list(1, 2, 3) filterm { x => list(true, false) } res19: list[list[int]] = list(list(1, 2, 3), list(1, 2), list(1, 3), list(1), list(2, 3), list(2), list(3), list()) 

i see can pass boolean list of size. filterm method?

also, there book/tutorial of scalaz bit more explanations?

this pretty old question. i'll answer in case else wondering.

you can find pretty explanation learn haskell good!. search filterm in link referenced.

in book, says following (you can kind of make out haskell syntax):

the filter function pretty bread of haskell programming (map being butter). takes predicate , list filter out , returns new list elements satisfy predicate kept. type this:

filter :: (a -> bool) -> [a] -> [a]

the predicate takes element of list , returns bool value. now, if bool value returned monadic value? whoa! is, if came context? work? instance, if every true or false value predicate produced had accompanying monoid value, ["accepted number 5"] or ["3 small"]? sounds work. if case, we'd expect resulting list come log of log values produced along way. if bool predicate returned came context, we'd expect final resulting list have context attached well, otherwise context each bool came lost.

filterm :: (monad m) => (a -> m bool) -> [a] -> m [a]

the predicate returns monadic value result bool, because it's monadic value, context can possible failure non-determinism , more! ensure context reflected in final result, result monadic value.

as book reference, read following scalaz brief tutorial: learning scalaz. if need further in depth explanation, go learn haskell book.

still doesn't make sense me filterm in scalaz example. explanation in haskell book makes complete sense.

edit: clarified didn't make sense.


Comments

Popular posts from this blog

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -

mongodb - How to keep track of users making Stripe Payments -