Hi Lance.
I used functional approaches in a 2009 customer project, with the
Guava library. Mainly map (transform in Guava) and select (filter in
Guava), but also the composite Comparator (Ordering in Guava). Having
to write a Function class for each getter method was so tedious.
That's why I investigated in the Jedi framework, and found its code
generator an appropriate tool. But Guava and Jedi use their own
Function/Functor interfaces, which means that I need to switch to Jedi
completely, or have an adapter that wraps a Jedi Functor in a Guava
Function. Therefore, I did not use Jedi back then.
This year, I am working on a new module of my company's software
product (a Flex/Java application), and am again tempted to use
functional approaches, partially because Flex provides them OOTB. In
my spare time and out of curiousity, I tested my understanding of the
Jedi code generation, by modifying it to create implementations of the
Guava Function interface. This way, I could use the Jedi code
generator with the Guava library. Of course, I did not want to change
too much, especially, I did not want to patch jedi-core. Therefore I
added in another Maven module "java-guava" an interface, also named
Functor, but in a different package, extending both Guava Function and
Jedi Functor (and Functor0 and Functor2, just extending their Jedi
counterpart). I managed to reach that goal with patching 3 jedi-
annotation classes. The main obstacle was that Function has apply()
and Functor has execute() method.
Then, I locally changed some of the newly written company code I am
working on, to see the difference "functional" makes. For the cases I
checked until now, there is little difference between Guava and Jedi,
so I might just use plain Jedi with unpatched code generation. I
showed a collegue side-by-side examples of what I named "imperative
Java" and "functional Java", and she said something like "it looks
strange, because I am not used to it. Similar to how a Java 5 for-each
loop looked strange, compared to an iterator loop." Well, she will
have to get used to it. ;-)
Regards,
Christian Semrau