Add `justLeft :: Either l r -> Maybe l`, `justRight :: Either l r -> Maybe r`
justLeft = Just `either` const Nothing
justRight = const Nothing `either` Just
These are different enough from fromLeft and fromRight, and wordy enough in their simple implementation, that I propose to export them as a matter of convenience from Data.Either.
There are existing eitherToMaybe :: Either a b -> Maybe b in package extra, and leftToMaybe, rightToMaybe in packages either, relude, and protolude.
I think I prefer the established names for these to yours, though they aren't wonderful either.
I think I'm in favor of having the functions.
The names match prior art in These of just{This,That,These,Here,There}. They feel awkward to me at first, but I like them better when I think of "just" as primarily acting as a synonym for "only" in a way that mnemonically shares a name with a constructor, rather than primarily being a constructor name. Like, it's saying "keep just the value from a Left", and the way it keeps it happens to be in a constructor named Just; it's not saying "turn a Left into a Just".
I also wouldn't object to leftToMaybe, rightToMaybe or leftToJust, rightToJust. I think I prefer *ToJust over *ToMaybe, and I'm not sure where I rank just* in relation to the others.
On Tue, 23 Dec 2025, Phil Hazelden wrote:
[57271?s=20&v=4] ChickenProp left a comment (haskell/core-libraries-committee#380)
I think I'm in favor of having the functions.
https://hackage.haskell.org/package/utility-ht-0.0.17.2/docs/Data-Either-HT.html#v:maybeLeft
I agree with @ChickenProp ... it'll probably require some getting used to (naming wise), but it's a common idiom.