excilys/androidannotations — Issue #27: Functional Programming ala jcurry
Author: pyricau
Created: 2012-01-06 16:06:21+00:00
State: open
Labels: Enhancement

Maybe we could provide some parts of "functional programming" into Java through AndroidAnnotations.

I'm thinking of doing a thing that would be a bit like what jcurry does (http://code.google.com/p/jcurry/). It uses project Lombok to transform annotated methods into Guava functions.

We could provide First class functions in generated code, based on some annotated method.

So, you would have something like this :

```
@EFunction
Integer myFunction(String param) {
}
```

And you would do :

```
Function myF = SomeGeneratedClass_.myFunction(activityInstance);

Integer result = myF.apply("Test");
```

The idea here is that we could then use some Java "functional" frameworks such as Guava, but also introduce Functions for some AndroidAnnotations features.

We could also detect whether Guava (or any other fwk) is in the classpath, and generate an instance of one class or another based on that. For example, we could have the AAFunction interface, and the AAGuavaFunction interface that extends Function from Guava and AAFunction. All those interfaces would have the same apply method signature.

This is really a draft, the idea is not mature yet, any comment / suggestion is welcome!

The First class function might be part of the "enhanced subclasses". In that case, we could create one instance per instance of enhanced subclass, so MyActivity_.myFunction(activity) would always return the same function instance if called with the same instance parameter.

Of course, static annotated method wouldn't need any instance param : `MyActivity_.myStaticMethod_()`