Where should whenJust go?

Ahn, Ki Yung kyagrd at gmail.com
Thu Jun 4 03:54:43 EDT 2009

Dear Haskellers,

I happened to defined a function whenJust whose definition is like this:

> whenJust :: (Monad m) => (a -> m ()) -> Maybe a -> m ()
> whenJust = maybe (return ())

while I was writing a fun utility to upload to hackage.

I had a strong feeling that someone must have defined this already,
so I used Hayoo, and I did find it:

XMonad.Core.whenJust :: Monad m => Maybe a -> (a -> m ()) -> m ()

The argument order is different I believe it is dong the same thing.

Shouldn't we add add whenJust to more general library regarding Monad
and Maybe, so that we can used it as a standard idiom?  I think its much
more readable writing "maybe (return ())" or "flip (maybe (return ()))".

  Ahn, Ki Yung

More information about the Libraries mailing list