Lambda Parameters of Unknown Arity

Beran, Sam E sam-beran at
Mon Jan 7 08:51:45 PST 2013

With the various functional interfaces in project lambda, it ends up being very difficult to work with functional interfaces of unknown arity.

One example where this would be very useful is a web routing API, such as Sinatra in Ruby. We would want to bind multiple parameters, based on their name or position:

    GET("/people/{id}", Long id -> {
         // perform request

As you can see, this would be a very nice api, but is very tricky to implement, because you must create a GET method with a new functional interface for each arity of method you'd like to accept. This leads to an ugly explosion of methods on the class. Here is an example:

Has there been any thought given to something like a MetaFunction class, which could be invoked dynamically via varargs? Ideally, my GET method above, would have the following signature:

    void GET(String route, MetaFunction handler) {
         //set up route here

This would be useful for many different libraries, and would be great to have first class support in the language for it! Apologies if this has been discussed before, I'm fairly new to the list.


More information about the lambda-dev mailing list