[Haskell-cafe] Maybe to Either -- is there a better way?

Tom Davies tgdavies at gmail.com
Mon Aug 2 10:14:55 EDT 2010

I find it convenient sometimes to convert a Maybe value to an Either thus (excuse the syntax, it's CAL, not Haskell):

maybeToEither :: a -> Maybe b -> Either a b;
maybeToEither errorValue = maybe (Left errorValue) (\x -> Right x);

but that seemingly obvious function isn't in Hoogle, AFAICT, so perhaps there's some other approach?


More information about the Haskell-Cafe mailing list