leftToMaybe/rightToMaybe
Herbert Valerio Riedel
hvr at gnu.org
Wed Aug 7 21:14:49 CEST 2013
On 2013-08-06 at 12:21:14 +0200, 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
Some minor nitpicking: IMHO, the naming is inconsistent with
respect to the existing functions:
listToMaybe :: [a] -> Maybe a
maybeToList :: Maybe a -> [a]
In these two cases, '[lL]ist' and '[mM]aybe' both denote types, whereas
in '{left,right}ToMaybe', 'left' is a constructor and 'Maybe' is a type.
However, I have no better naming alternative to offer.
-- hvr
More information about the Libraries
mailing list