|
|
|
|
|
by VLM
3751 days ago
|
|
My shipping boxes hold an even number of widgets, but I "have to" sell odd quantities and those need expensive mil spec styrofoam peanuts added to fill the hole. Here, have an array of possible shipment sizes. Given that array, if its shipping an odd number of widgets I wanna add an additional half widget shipping charge. newshipping = oldshipping.select{|i| i % 2 == 1 }.map{|i| i + 0.5 } My ridiculous fictional writing about shipping widgets is way more confusing than the idea that you can select and then chain right into a map. This probably looks really weird to a java guy but its not really all that mysterious. I wonder what that looks like in Java. |
|
List<Double> newshipping = oldshipping.stream().filter(i -> i % 2 == 1).map(i -> i + 0.5d).collect(Collectors.toList());
a bit more verbose but the essential chaining idea is there...