My favorites | Sign in
Project Home Downloads Wiki Issues Source
READ-ONLY: This project has been archived. For more information see this post.
Project Information
Members
Featured
Downloads
Wiki pages
Links

NEW: Version 1.3.1 Available in Maven Central

News



What Is Funcito?

Funcito is a Java library that simplifies access to your favorite functional programming APIs by wrapping Java methods as the function-type objects defined in those libraries.

Rather than creating another functional programming API, Funcito makes it easy to define function-type objects that wrap existing methods. As a result, your code has less noise and clutter of anonymous inner classes, annotations, etc. And your code remains safe for automated-refactoring, since there is no String-based reflection or forced naming conventions.

Using Funcito

Suppose you have a simple POJO with several Getter methods:

 public class Worker {
    private int badgeNum;
    private String lastName;
    private String firstName;
    private boolean employee;
 

public Worker(int badgeNum) { this.badgeNum = badgeNum; } // ... setters would be here too...

public int getBadgeNum { return badgeNum; } public String getLastName; { return lastName; } public String getFirstName { return firstName; } public boolean isEmployee { return employee; } }

If you wanted to filter a collection of Worker objects to get the Workers who are employees, you could use the functional capabilities of Google Guava (examples for the other supported functional APIs are found in the Usage Notes):

 Collection<Worker> employees = Collection2.filter(allWorkers, isEmployeePredicate);
 

But first you need to create the isEmployeePredicate object. Implementing the Predicate interface normally requires an anonymous inner class:

 Predicate<Worker> isEmployeePredicate = new Predicate<Worker> () {
    @Override
    public boolean apply(Worker worker) {
        return worker.isEmployee();
    }
 }
 

That's six lines of code, lots of indenting -- basically a lot of noise. Funcito allows you to obtain an equivalent Predicate in just a single clear line:

 Predicate<Worker> isEmployeePredicate = predicateFor( callsTo(Worker.class).isEmployee() );
 

Similarly, Funcito can create a Guava Function to get the last names of all employees:

 Function<Worker,String> lastNamesFunc = functionFor( callsTo(Worker.class).getLastName() );
 List<String> lastNames = Lists.transform(allWorkers, lastNamesFunc);
 

As you start using methods as Functions or Predicates, you will end up redefining them in multiple places. And you may also find yourself functionally wrapping several properties from the same class. Why not put related reusable Function/Predicate declarations together as static declarations in a new class? Then you can statically import your Functions or Predicates at will.

 public class Workers {
    private static final Worker CALLS_TO = callsTo(Worker.class); // a proxy stub for Function creation
 

public static final Function<Worker,Integer> GET_BADGE_NUM = functionFor(CALLS_TO.getBadgeNum()); public static final Function<Worker,String> GET_LAST_NAME = functionFor(CALLS_TO.getLastName()); public static final Function<Worker,String> GET_FIRST_NAME = functionFor(CALLS_TO.getFirstName()); public static final Predicate<Worker> IS_EMPLOYEE = predicateFor(CALLS_TO.isEmployee()); }

Capabilites

Supported Functional Programming Libraries

Funcito currently supports the following libraries that have functional programming capabilities:

  • Google Guava Function and Predicate interfaces
  • Functional Java the F (function) interface and Effect (new for 1.3!)
  • Jedi-core Functor and Filter interfaces and Command (new for 1.3!)
  • Play! Framework 2 F.Function interface and Callback (new for 1.3!)
  • Collection-generic Transformer and Predicate interfaces and Closure (new for 1.3!)
  • RxJava Function1 and Action1 interfaces (all new for 1.3!)

In future releases, we hope to add the following interfaces:

  • Plain access of Methods for those who want to work directly with Java Method objects, without using String-based reflection
  • J2SE zero-argument functional interfaces such as Runnable or Callable
  • Your favorite library with functional programming support that defines its functional-types as Java interfaces. Contact us.

Supported Code Generation Libraries

The Funcito syntax for generating the functional-type objects is enabled by the use of code generation libraries. Any of your projects that use the Hibernate or Spring frameworks are already using one of the two supported code-generation frameworks. You can use either one, as you prefer:

If you do not want to depend on external Code-gen libraries and don't mind being restricted to wrapping methods on interfaces only, Funcito will revert to using Java dynamic Proxies as an alternate "code-generation library". Instructions on explicitly configuring a code proxying mechanism are found in "Configuring a Proxy Provider" if you need to override Funcito's internal search and selection rules.

License

Funcito is released under the Apache 2.0 open source license.

Continuous Integration

Continuous Integration services are generously provided in the cloud by CloudBees through their free FOSS program. You may find our nightly builds, including unit test coverage reports on our CI Server page at their site.

Your Support of Funcito is Welcome

Powered by Google Project Hosting