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

Ivan Lazar Miljenovic ivan.miljenovic at gmail.com
Tue Aug 3 05:27:41 EDT 2010

Yitzchak Gale <gale at sefer.org> writes:

> Tom Davies wrote:
>>> I find it convenient sometimes to convert a Maybe
>>> value to an Either
> maybeToEither = flip maybe Right . Left

Remember, some people don't like flip! :p

maybeToEither = (`maybe` Right) . Left

> While useful, I think its ubiquity to simplicity ratio is not
> high enough to justify either depending on MissingH
> just for that, or adding it to a base library.

Just like the swap :: (a,b) -> (b,a) function a lot of people were
discussing on libraries@?

In general, I agree.

> However, if your personal style makes this so
> ubiquitous as to override its simplicity, go ahead
> and upload it to Hackage, perhaps others will
> also benefit.

Just give it a good name, rather than "fooToolkit", "barToolkit", etc.

Ivan Lazar Miljenovic
Ivan.Miljenovic at gmail.com

More information about the Haskell-Cafe mailing list