Either
is typically the sum-type equivalent of Pair
, which is a tuple that's limited to 2 fields. I don't think Either
is very interesting—I'd rather see a sum-type equivalent to tuples.
But Either
also isn't a very good way to model Result
, or any other sum type with 2 fields. I suspect you wouldn't model Point
with a Pair<Float, Float>
or a (Float, Float)
most of the time either. point.0
or point.first
is much less clear than point.x
. Adding semantic names, which makes the abstraction less generic, is actually helpful.
(Similarly, you could replace Optional
with typealias Optional<Value> = Either<Value, Void>
, but I don't think that'd be a good idea)