Snippet 1:
Optional.of(s).map(str -> str).orElse("");
Snippet 2:
Optional.of(s).map(str -> str).orElse(Optional.empty());
Snippet 3:
Optional.of(s).map(str -> Optional.of(str)).orElse("hello");
Snippet 1 is compiling fine but Snippet 2 & Snippet 3 compile with type incompatibility errors. While it's good that Snippet 2 & Snippet 3 fail, I do not understand how they are evaluated. In other words, I think I am missing some basics in terms of how the lambdas themselves are chained/invoked. Would appreciate if someone could help.