Open mstksg opened 7 years ago
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 --
censor
, or eitherToMaybe
-- there's no universally agreed nameeither (const Nothing) Just
or 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 :)
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 inData.Either
.leftToMaybe
/rightToMaybe
are really the same level of importance aslistToMaybe
.swapEither
is just as ubiquitous asswap
. AlsomaybeToLeft
/maybeToRight
might as well be there too, matchingmaybeToList
(with an extra parameter). I've re-written some variety ofmaybeToLeft
andmaybeToRight
so many times I can hardly count >.<