Java Reference
In-Depth Information
Function<String,String> defaultString = s -> {
if(s.isEmpty()) {
return "0";
} else {
return s;
}
};
converter = eliminateNondigits
.andThen(defaultString);
.andThen(Integer::parseInt);
}
In that example, the compiler ensures us that converter is set before we leave the if/else chain. No
matter how many cases we have, and no matter how complex the code may get in each case, we know that
each and every case will set a converter .
The type system is a powerful tool in the hands of a functional programmer because it allows you to
enforce the constraints of the system and reason about how they are applied. Use the type system to the best
advantage that you can, and avoid circumventing it.
Search WWH ::




Custom Search