
30 Nov
2011
30 Nov
'11
2:11 a.m.
This particular pattern crops up a lot for me. Does it for anyone else? I (half-heartedly) propose adding to Control.Monad the following:
-- | A variation of 'when' for 'Maybe a'. whenJust :: (Monad m) => Maybe a -> (a -> m ()) -> m () whenJust = flip (maybe (return ()))
so that I can write:
whenJust (Map.lookup k m) $ \ a -> do ...
instead of say:
case Map.lookup k m of Nothing -> return () Just a -> do ...
which is not only nicer on the eyes, but also saves me a valuable level of indentation. Discussion period: 2 weeks. Cheers, /Liyang