haskell - Using when/unless without saving the result of a Monadic action -
is there way write without variable x?
foo = x <- checker bar when x dostuff i'm imagining similar lambdacase:
foo' = checker bar >>= \case true -> dostuff _ -> return () but without second case pattern, obviously.
the straightforward answer desugar do hand, , see if can write code that's equivalent prettier. do desugars to:
checker bar >>= \x -> when x dostuff so, answer have checker bar >>= f, f equivalent
\x -> when x dostuff well, that's lot partially applying when, right? except want supply second argument instead of first, need flip it:
checker bar >>= flip when dostuff
Comments
Post a Comment