An Either Monad in Java
I have a nit-pick with the logic in your Either.or(A) method. You have:


public Either&lt;A&gt; or(A value) {
    return new Either&lt;A&gt;(this.value, value);
}



but, since Either is immutable (oh, should Either be a final class? ... I think so...), it makes sense that the or method can return the exact instance if it is valid.... why does it have to create a new instance each time? In a stream that can create a lot of GC churn....

I would write that method:

public Either&lt;A&gt; or(A value) {
    return value == null ? this : new Either&lt;A&gt;(value);
}


I know that essentially duplicates the constructor, but, doing it this way avoids the constructor in (hopefully) many places entirely.

This leads on to your question:


  One question I wasn't sure of the the semantics of multiple calls.
  Should I carry along the original default value, or does each new
  value become the default? So in psuedo code, should

Either.with("A").or("B").or(null)

  
  result in "A" (the original default) or "B"? I thought "B" made more
  sense.


If the or(A) method does not need to construct a new instance, then it makes sense to me that the semantics should return "A", since that allows skipping new instances for "B" and null.