Use forM_ from Data.Foldable , which has the following type:
forM_ :: (Monad m, Foldable t) => ta -> (a -> mb) -> m ()
Maybe implements the Foldable class, which behaves like a list with zero or one element, so when you specialize t in the above signature of type Maybe , you get:
forM_ :: (Monad m) => Maybe a -> (a -> mb) -> m ()
You use it as follows:
forM_ maybeUri $ \uri -> download uri outputPath
It will only perform an action if the Maybe value is Just .
source share