June 2018
Intermediate to advanced
280 pages
7h 46m
English
The strategy can be replaced by a function. In the following example code, we apply a 10% discount strategy to all our prices:
jshell> Function<Double, Double> tenPercentDiscount = x -> x * 0.9;tenPercentDiscount ==> $Lambda$217/1990160809@4c9f8c13jshell> List.<Double>of(5.4, 6.27, 3.29).stream().map(tenPercentDiscount).collect(Collectors.toList())$98 ==> [4.86, 5.643, 2.9610000000000003]
Read now
Unlock full access