Tool to reduce the noise of function creation

76 views
Skip to first unread message

kbwelker

unread,
Feb 3, 2012, 2:35:23 PM2/3/12
to Functional Java
As I have started to invest in using functional idioms in Java, I
discovered that oftentimes the creation of function-type objects like
a fj.F 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. So I have created a
library, Funcito, to simplify function creation in existing functional
libraries such as FJ. It is found at:

http://funcito.googlecode.com

As an example take the following code before Funcito:

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

With Funcito this gets replaced by:

F<String, Integer> lengthFunction =
fFor( 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);
F<CharSequence, Integer> length = fFor( callsTo.length() );
F<CharSequence, String> toString = fFor( callsTo.toString() );
Message has been deleted
Message has been deleted
Message has been deleted

kbwelker

unread,
Apr 5, 2012, 1:17:04 PM4/5/12
to functio...@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
Functional Java (or Jedi).  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 "

And please feel free to visit and contribute to the Funcito Google
Group.  I am incubating some ideas that I hope would make Funcito even
more useful for Functional Java users as well as users of other FP-
libraries:

http://groups.google.com/group/funcito
Reply all
Reply to author
Forward
0 new messages