Proposal: add Control.Monad.whenJust ∷ (Monad m) ⇒ Maybe α→(α→ m ()) → m ()
haskell.org at liyang.hu
Wed Nov 30 17:51:03 CET 2011
Mikhail Vorozhtsov <mikhail.vorozhtsov <at> gmail.com> writes:
> On 11/30/2011 02:11 PM, Liyang HU wrote:
> >> whenJust :: (Monad m) => Maybe a -> (a -> m ()) -> m ()
> We already have it. See Data.Foldable.forM_
Good point! Hadn't crossed my mind that Maybe is Foldable; kind of obvious
Evan Laforge <qdunkan <at> gmail.com> writes:
> I prefer it to Foldable.forM_ because it's explicit about the type it
> takes, forM_ sounds too much like a loop.
Well, forM_ is just mapM_ flipped, and shurely we map over Maybe all the time?
I'm much less inclined towards my proposal now, with the possible proviso that
some people might find Foldable confusing. Also, if we go down the route of
whenJust, why not whenLeft and whenRight (and so on) too?
More information about the Libraries