July 2018
Intermediate to advanced
400 pages
12h 14m
English
Look back at the example using zip in Listing 19.7. Imagine implementing the same task in the object-oriented paradigm or its broader class, called imperative programming. In Java, for example, this task might look something like this:
List<String> employees = Arrays.asList("Denny", "Claudette", "Peter");
List<String> shirtSizes = Arrays.asList("large", "x-large", "medium");
Map<String, String> employeeShirtSizes = new HashMap<>();
for (int i = 0; i < employees.size; i++) {
employeeShirtSizes.put(employees.get(i), shirtSizes.get(i));
}
At first glance, the imperative version here may look like it accomplishes the task in roughly the same number of lines as the functional version in Listing 19.7. But ...
Read now
Unlock full access