guard package:extra

Either lifts a value into an alternative context or gives a minimal value depending on a predicate. Works with Alternatives.
guarded even 2 == [2]
guarded odd 2 == Nothing
guarded (not.null) "My Name" == Just "My Name"
A variant of guarded using Functor-wrapped values.
guardedA (return . even) 42    == Just [42]
guardedA (return . odd) 42     == Just []
guardedA (const Nothing) 42    == (Nothing :: Maybe [Int])