ANN: Control.Monad.IfElse

Provides useful anaphoric and monadic versions of if-else and when, as well as infix operators for the actions to allow things like this: -- Allow the clause to be in m a whenM (Gtk.widgetIsFocus win) $ do this that -- anaphoric if. If the condition is nonempty, pass the conditional value to the "then" clause, otherwise do an action that requires no parameter. aif (lookup name list) (\file -> Right `liftM` hGetLine file) (do f <- openFile name l <- hGetLine file return $ Right (f,l)) -- infix version of Control.Monad.When (x>5) >>? putStrLn x -- infix version of anaphoric when lookup name list >>=? \value -> putStrLn value -- infix version of anaphoric whenM Gtk.widgetIntersect win rect >>=>>? \intersectingRectangle' -> Gtk.invalidate intersectingRectangle'

Hi, Am Montag, den 22.12.2008, 09:24 -0500 schrieb Jeff Heard:
Provides useful anaphoric and monadic versions of if-else and when, as well as infix operators for the actions to allow things like this:
nice package. Especially awhen :: Monad m => Maybe a -> (a -> m ()) -> m () is something I define in almost every project. Note that the documentation: ========== Chainable anaphoric when. Takes a maybe value. if the value is Just x then execute action x , then return True . otherwise return False . ========== does not match the implementation. And looking at the code, you could, you want, build your more special functions upon your more general ones, e.g.: awhen mb action = aif mb action (return ()) Greetings, Joachim -- Joachim "nomeata" Breitner mail: mail@joachim-breitner.de | ICQ# 74513189 | GPG-Key: 4743206C JID: nomeata@joachim-breitner.de | http://www.joachim-breitner.de/ Debian Developer: nomeata@debian.org
participants (2)
-
Jeff Heard
-
Joachim Breitner