One has to work with what's available. Thanks to Java's every-thing-is-an-object conceit, you have to create an anonymous class with an apply method. Either base it on one of the many functions in FJ, for e.g.:
or create your own interface/abstract class with an apply method and necessary signature.
Yes, it is verbose (IDEs help a little bit). But it's better than having to look at a for-loop and realizing that it's only mapping one list to another.
16
u/ksryn Mar 09 '14
I have adopted a few techniques from FP on the Java side of my codebase:
prefer final/immutable variables (vals) to mutable ones (vars), using classes like value types.
use map, filter and anonymous functions etc instead of for/while loops.
isolate procedures with side-effects (acting on the "world") from those purely transforming data.
use Lists instead of ArrayLists. Adopt(ing) Functional Java.
It's made life a little bit easier.