leftToMaybe/rightToMaybe
Erik de Castro Lopo
mle+hs at mega-nerd.com
Wed Aug 7 06:06:26 CEST 2013
Christopher Done wrote:
> How about popping these in Data.Either?
>
> -- | Maybe get the left side of an Either.
> leftToMaybe :: Either a b -> Maybe a
> leftToMaybe = either Just (const Nothing)
>
> -- | Maybe get the right side of an Either.
> rightToMaybe :: Either a b -> Maybe b
> rightToMaybe = either (const Nothing) Just
+1
And while we're at it:
isLeft :: Either a b -> Bool
isLeft (Left _) = True
isLeft (Right _) = False
isRight :: Either a b -> Bool
isRight (Left _) = False
isRight (Right _) = True
Erik
--
----------------------------------------------------------------------
Erik de Castro Lopo
http://www.mega-nerd.com/
More information about the Libraries
mailing list