I found myself wanting this tiny little function, but it doesn't seem to be in Data.Maybe
. Is it somewhere else?
splat :: (a -> Bool) -> a -> Maybe a
splat c a
| c a = Just a
| otherwise = Nothing
I found myself wanting this tiny little function, but it doesn't seem to be in Data.Maybe
. Is it somewhere else?
splat :: (a -> Bool) -> a -> Maybe a
splat c a
| c a = Just a
| otherwise = Nothing
The package monadplus contains exactly this function, named
partial
:would be a shorter, more general definition, if you decided you want this. But just using
guard
in-line wherever you need it is likely to be more convenient anyway.