Suppose I have several methods that each one returns optionally. I want to bind them together so that if one of them returns Optional with a value, then the chain should stop propagating and should stop at that point. For example, let's say that f1, f2, f3 each returns Optional.
If I do something like this,
Optional<T> result = f1.or(f2).or(f3);
I see that even if f2 returns the Optional.of (t) parameter, f3 is still called.
I want him to act like a short trailing expression, but that doesn't work.
Can anyone help me with this.
source
share