Is there a name for "maybe mzero return"?
optparse-applicativehashoistMaybe.monad-extrashasliftMaybe.errorshasjustZ.IfElsehasmaybeMP
All of the above is one and the same.
The obvious option would be
maybeAlt :: Alternative f => Maybe a -> fa maybeAlt = maybe empty pure And this is a special case of the next, similar to asum .
import Data.Monoid import Control.Applicative foldAlt :: (Foldable f, Alternative m) => fa -> ma foldAlt = getAlt . foldMap (Alt . pure) The reason you won't find anywhere is pure a <|> x === pure a . So itโs good for this and not much more. It could be improved to
foldAltMap f = getAlt . foldMap (Alt . f) or
foldrAltMap f = foldr (\xr -> fx <|> r) empty but itโs probably easier to understand.