Tool to reduce the noise of Functor/Filter creation

17 views
Skip to first unread message

kbwelker

unread,
Feb 3, 2012, 2:55:16 PM2/3/12
to jedi
As I have started to invest in using functional idioms in Java, I
discovered that oftentimes the creation of function-type objects like
a Functor often add as much noise and complexity to the source code as
they reduce when they are used to replace for-loops. This bothered
me, since often the function I am trying to create is simply a wrapper
around a simple method that already exists. I know Jedi has the very
nice @Jedi/@Sith annotations to help, but some project teams may wish
to avoid the usage of APT that complicates project builds and requires
adherence to a strict naming convention or else using String-args in
the annotation which are harder to refactor using tools.

So I have created a library, Funcito, to simplify function creation in
existing functional libraries such as Jedi Core. It is found at:

http://funcito.googlecode.com

As an example take the following code before Funcito (and assuming non-
usage of @Jedi*):

Functor<String, Integer> lengthFunction = new Functor<String,
Integer>() {
public Integer execute(String string) {
return string.length();
}
};

With Funcito this gets replaced by:

Functor<String, Integer> lengthFunction =
functorFor( callsTo(CharSequnce.class).length() );

If you have more than one method you want to wrap on the same
interface or class, notation can be expressed even more concise and
readable:

CharSequence callsTo = callsTo(CharSequence.class);
Functor<CharSequence, Integer> length =
functorFor( callsTo.length() );
Functor<CharSequence, String> toString =
functorFor( callsTo.toString() );

kbwelker

unread,
Feb 3, 2012, 3:00:16 PM2/3/12
to jedi
Sorry, text-wrapping obscures the beauty quite a bit. Hopefully you
get the picture anyway.

Lance Walton

unread,
Feb 3, 2012, 3:35:13 PM2/3/12
to jed...@googlegroups.com
This is very nice. I'll soon update the Jedi pages to reference functito as an alternative method of creating the Functors and Filters.

Regards,

Lance

kbwelker

unread,
Feb 3, 2012, 4:18:23 PM2/3/12
to jedi
Thanks and glad you like it. I hope to expand my support to Commands
as well, and who knows what else. Btw, it's "Funcito" not
"Functito" :-)

-- Kevin

kbwelker

unread,
Apr 9, 2012, 12:37:54 PM4/9/12
to jed...@googlegroups.com
For those who are interested, Funcito v 1.0.2 has been released.  This release fixes a bug that inadvertently left a run-time dependency on Google Guava, even if you were using Funcito as an add-on for
Jedi (or Functional Java).  The project is still located at:

http://funcito.googlecode.com

This version has also been deployed to Maven Central:

http://search.maven.org

and search for "funcito ".

I thought I posted this once before a few days ago.  If it was deleted as SPAM, please let me know and I will gladly stop posting release-updates.  I just thought this update in particular was especially helpful to the Jedi user community, as it removed a dependency that Jedi users should not be forced to have.

Channing Walton

unread,
Apr 9, 2012, 12:42:04 PM4/9/12
to jed...@googlegroups.com
Excellent stuff. 

We are interested in updates to your project, keep them coming.

Channing
Reply all
Reply to author
Forward
0 new messages