Proposal: Add isLeft/isRight to Data.Either

Herbert Valerio Riedel hvr at gnu.org
Tue Dec 4 23:02:07 CET 2012


Simon Hengel <sol at typeful.net> writes:

> Hi,
> I propose to add isLeft/isRight to Data.Either, with the obvious
> definitions:
>
>     isLeft :: Either a b -> Bool
>     isLeft (Left  _) = True
>     isLeft (Right _) = False
>
>     isRight :: Either a b -> Bool
>     isRight (Left  _) = False
>     isRight (Right _) = True
>
> There has been a discussion on that before [1].  While I agree that
> fromLeft/fromRight are moot, I don't see issues with isLeft/isRight.
>
> Personally I care mostly about isLeft, but for orthogonality I propose
> to add both isLeft and isRight.

+1

btw, what I've been missing even more than isLeft/isRight is something
like

	leftMaybe :: Either a b -> Maybe a
	leftMaybe (Left x) = Just x
	leftMaybe _        = Nothing
	
	rightMaybe :: Either a b -> Maybe b
	rightMaybe (Right x) = Just x
	rightMaybe _         = Nothing
	


cheers,
  hvr



More information about the Libraries mailing list