I have three java8 Optionals, and want to return whichever one is actually present in a preferred order. It seems like there should be an easy way to chain them like so:
return optionalA.orElseIfPresent(optionalB).orElseIfPresent(optionalC);
if all three are empty, then an Optional.empty()
ought to be returned.
the existing orElse and orElseGet are not really up to the task - they must return an actual value, so it's not possible for the remaining fallbacks to be Optionals themselves.
In the worst case I can have a long list of ifPresent() checks, but there just seems like there's a better way to go about it?