haskell-issues
haskell-issues copied to clipboard
basic Either combinators should be in Data.Either
There are a lot of useful combinators for Either in the either package http://hackage.haskell.org/package/either-4.4.1.1/docs/Data-Either-Combinators.html but they really should be in Data.Either.
leftToMaybe/rightToMaybe are really the same level of importance as listToMaybe. swapEither is just as ubiquitous as swap. Also maybeToLeft/maybeToRight might as well be there too, matching maybeToList (with an extra parameter). I've re-written some variety of maybeToLeft and maybeToRight so many times I can hardly count >.<
swap actually sounds like it ought to be generalized into Data.Bifunctor, but that's not possible just by the class definition. Do all instances have that possibility in common?
Do all instances have that possibility in common?
Definitely not. E.g. Const is a bifunctor, but you can't write Const a b -> Const b a.
@mstksg I found 9 uses of leftToMaybe on Github (not counting occurrences in various preludes) and about 55 uses of rightToMaybe. This said, they are still used about 5–10 times less often than fromLeft and fromRight (which aren't in base yet but will be added in next release). Personally I don't feel they're particularly useful (and I think I've never used them myself); this makes me hardly a good candidate for “officially” proposing them (as I wouldn't be able to defend their inclusion convincingly). However, I'll keep this issue open in case somebody else feels more enthusiastic about them.
I doubt you'd find a bunch of rightToMaybe, because --
- I've always seen it used by other names, like
censor, oreitherToMaybe-- there's no universally agreed name - It's short enough that people usually just write out
either (const Nothing) Justor something else -- i've seen files where people use it several times in the same file, or just defined a local alias.
I've had to write Either e a -> Maybe a in many different situations, but mostly when writing a big Maybe do block :)