all right... and ...rights
There is now a proliferation of right... and ...Right methods in
the class. This makes for a really wide interface. I want to consider
a simplification.
Note on #getRight(): that seems OK and should probably stay.
For everything else, what about a #swap() (or maybe a better name) method like so:
// for any...
final Either<L,R> e = ...;
// let...
final Either<R,L> ep = e.swap();
// then...
assert e.isLeft() != ep.isLeft();
assert e.isLeft() || e.getRight().equals(ep.getLeft());
assert !e.isLeft() || e.getLeft().equals(ep.getRight());
So, rather than, e.g.:
e.rightOrElse("other");
e.maybeRight();
You would use:
e.swap().orElse("other");
e.swap().maybe();
Here is something interesting:
Either<Integer, String> e =
Either.of(Something::thatMightThrow)
.swap().map(RuntimeException::getMessage)
.swap()
.map(My::method)
...
...
;
Without #swap(), Either would need a #rightMap(..) or similar to
achieve the above.
I am not fully this is a better interface model. Would like to
see comments from others before making a decision.
all right... and ...rights
There is now a proliferation of right... and ...Right methods in
the class. This makes for a really wide interface. I want to consider
a simplification.
Note on #getRight(): that seems OK and should probably stay.
For everything else, what about a #swap() (or maybe a better name) method like so:
So, rather than, e.g.:
You would use:
Here is something interesting:
Without #swap(), Either would need a #rightMap(..) or similar to
achieve the above.
I am not fully this is a better interface model. Would like to
see comments from others before making a decision.