3 ms·
I agree 100% that it is a specialized either. I would argue that either is inferior because programmers empirically won't be bothered remembering that Left = E
by benjaminjackman 12y ago
I agree 100% that it is a specialized either.
I would argue that either is inferior because programmers empirically won't be bothered remembering that Left = Err and Right = Ok. Also fixing your Left to conform to a common error type which supports chaining is directly is also pretty important. This can be accomplished in a few different ways, but it's going to be done so often that Either ends up never being used for anything other than Results base class / Result is implemented as a type-class on either, with crappy names for error and ok.
Overally though I dislike Either, because to me, it is a symptom of a language lacking a way to declare anonymous type disjunctions inline[1], just like things like std::pair indicates a language lacks tuples.
1: Something like
def parseToken : ParseError | Int | String
looking at that maybe with inline type disjunctions the need for Result itself melts away.