Proposal: Add isLeft/isRight to Data.Either
Andreas Abel
andreas.abel at ifi.lmu.de
Tue Dec 4 23:12:25 CET 2012
On 04.12.12 5:02 PM, Herbert Valerio Riedel wrote:
> 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
I have not been missing these, but +1.
--
Andreas Abel <>< Du bist der geliebte Mensch.
Theoretical Computer Science, University of Munich
Oettingenstr. 67, D-80538 Munich, GERMANY
andreas.abel at ifi.lmu.de
http://www2.tcs.ifi.lmu.de/~abel/
More information about the Libraries
mailing list