Add Control.Monad.forM and forM_
authorDon Stewart <dons@cse.unsw.edu.au>
Thu, 24 Aug 2006 08:11:18 +0000 (08:11 +0000)
committerDon Stewart <dons@cse.unsw.edu.au>
Thu, 24 Aug 2006 08:11:18 +0000 (08:11 +0000)
commitb5dd194466259e21a422af356f8d2e83bfd85a09
tree05346ce5a31acf030256e736cdea8e17029d9221
parentf77ec3f03eed4749d476a845fafa0ffdd8eb7e2a
Add Control.Monad.forM and forM_

flip mapM_ is more and more common, I find. Several suggestions have
been made to add this, as foreach or something similar. This patch
does just that:

    forM  :: (Monad m) => [a] -> (a -> m b) -> m [b]
    forM_ :: (Monad m) => [a] -> (a -> m b) -> m ()

So we can write:

    Prelude Control.Monad> forM_ [1..4] $ \x -> print x
    1
    2
    3
    4
Control/Monad.hs