isLeft/isRight (Was: leftToMaybe/rightToMaybe)
amindfv at gmail.com
amindfv at gmail.com
Wed Aug 7 15:33:12 CEST 2013
El Aug 7, 2013, a las 4:26, Henning Thielemann <lemming at henning-thielemann.de> escribió:
>
> On Wed, 7 Aug 2013, Erik de Castro Lopo wrote:
>
>> In the second link above you wrote:
>
> I have included both links since the discussion in November continued in December.
>
>
>>> It would be a good opportunity to check how these packages use isLeft and
>>> isRight. E.g. if they use them in connection with fromLeft and fromRight
>>> then this would be an argument for me to exclude isLeft and isRight as
>>> well.
>>
>> My main usage of isLeft/isRight is in HSpec tests where I write:
>>
>> value1 `shouldSatisfy' isLeft
>> value2 `shouldSatisfy' isRight
>
> Yes, from what I have seen in some packages, testing seems to be the most sensible usage of 'isLeft' and 'isRight'. In other contexts 'isLeft' is usually combined with a non-total 'fromLeft', which is certainly a bad idea.
>
Another use, where I've defined isLeft in the past, is checking that a set of computations was successful, e.g. "if all isRight foo"
+1 to all of these (although I could take or leave mapEither)
-Tom
>
>> I would also be opposed to a fromLeft defined anything like fromJust:
>>
>> Data.Maybe.fromJust :: Maybe a -> a
>>
>> but would not be opposed to a fromLeft defined as John Wiegley suggested:
>>
>> fromLeft :: a -> Either a b -> a
>> fromLeft _ (Left x) = x
>> fromLeft x _ = x
>
> It looks indeed better than the non-total fromLeft. On the other hand the name would be inconsistent with fromJust, and the total fromLeft could be written as:
>
> fromLeft x = either (const x) id
>
> or using the proposed maybeLeft as
>
> fromLeft x = fromMaybe x . maybeLeft
>
> I don't know how often you need fromLeft.
>
> _______________________________________________
> Libraries mailing list
> Libraries at haskell.org
> http://www.haskell.org/mailman/listinfo/libraries
More information about the Libraries
mailing list