Either lifts a value into an alternative context or gives a minimal value depending on a predicate. Works with Alternatives.
guarded even 3 :: [Int][]guarded even 2 :: [Int][2]guarded (const True) "hello" :: Maybe StringJust "hello"guarded (const False) "world" :: Maybe StringNothing
You can use this function to implement smart constructors simpler:
newtype HttpHost = HttpHost
{ unHttpHost :: Text
}
mkHttpHost :: Text -> Maybe HttpHost
mkHttpHost host = HttpHost <$> guarded (not . Text.null) host