Is it possible to replace a series of if-else clauses such as the firstMatchedValue method below
foo() {
String value = firstMatchedValue("input");
// Do something useful.
}
String firstMatchedValue(String bar) {
if (<condition1>) {
return "value1";
} else if (<condition2>) {
return "value2";
}
return "value3";
}
with a lambda expression with structure similar to the following placeholder code?
foo() {
String value = Optional.of("input")
.someMethod(bar -> <condition1> return "value1")
.someMethod(bar -> <condition2> return "value2")
.orElse("value3")
}