July 2023
Intermediate to advanced
276 pages
6h 55m
English
If we don’t consider the exceptions for a moment, refactoring the imperative style code to functional style code is easy. We have a list of IATA codes, we can invoke the stream method on the list, call map to get the name for a given IATA code, and then call map again to convert the name to uppercase, and finally use the toList method to place the result in a list. Code, like life, is easy when we don’t have to deal with errors. But fun without the risk of failure isn’t an option.
Using the Stream API with code that throws exceptions poses some serious challenges. Let’s use the functional style to rewrite the imperative solution and see what issues pop up:
| | public static List<String> ... |
Read now
Unlock full access