Use forM_
from Data.Foldable
, which has the following type:
forM_ :: (Monad m, Foldable t) => t a -> (a -> m b) -> m ()
Maybe
implements the Foldable
class, behaving like a list with zero or one elements, so when you specialize the t
in the above type signature to Maybe
you get:
forM_ :: (Monad m) => Maybe a -> (a -> m b) -> m ()
You use it like this:
forM_ maybeUri $ \uri -> download uri outputPath
It will only run the action if the Maybe
value turns out to be a Just
.