diff --git a/src/Utils.hs b/src/Utils.hs index d8545175e..bd6f8171f 100644 --- a/src/Utils.hs +++ b/src/Utils.hs @@ -955,20 +955,23 @@ deepAlt altFst _ = altFst maybeEmpty :: Monoid m => Maybe a -> (a -> m) -> m maybeEmpty = flip foldMap --- The more general `find :: Foldable t => (a -> Bool) -> t a -> Maybe a` +-- | A more general variant of `find :: Foldable t => (a -> Bool) -> t a -> Maybe a` filterMaybe :: (a -> Bool) -> Maybe a -> Maybe a filterMaybe c r@(Just x) | c x = r filterMaybe _ _ = Nothing --- | also referred to as whenJust and forM_ --- also see `foldMapM` if a Monoid value is to be returned --- also see `forMM_` if the maybe is produced by a monadic action +-- | also referred to as `whenJust` and `forM_`; +-- also see `foldMapM`, if a Monoid value is to be returned; +-- also see `forMM_`, if the maybe is produced by a monadic action whenIsJust :: Monad m => Maybe a -> (a -> m ()) -> m () whenIsJust (Just x) f = f x whenIsJust Nothing _ = return () --- ifNothingM m d a = maybe (return d) a m -ifNothingM :: Monad m => Maybe a -> b -> (a -> m b) -> m b -- more convenient argument order as compared to maybeM +-- | -- Often a more convenient argument order as compared to the not quite identical `maybeM` +-- @ +-- ifNothingM m d a = maybe (return d) a m +-- @ +ifNothingM :: Monad m => Maybe a -> b -> (a -> m b) -> m b ifNothingM Nothing dft _ = return dft ifNothingM (Just x) _ act = act x