Optional<String> result = returnsAnOptional();
if (result.isPresent()) {
log.info("result is {}", result.get());
}
// and
returnsAnOptional().map(r -> log.info("result is {}", r);
Optionals are a bit different though, since they don't provide a way to explicitly handle errors, just wrap the `null` value if it exists and force you to be more explicit about it.
I don't know that there's a clean way to do the Either monad in Java without algebraic data types. You could certainly make a wrapper class that maybe has an optional `Left` and `Right` private variable and then make a `map` that handles the unboxing of those, but I think that might be a bit messy.