Lambda Parameters of Unknown Arity

Remi Forax forax at univ-mlv.fr
Mon Jan 7 09:48:35 PST 2013


On 01/07/2013 06:22 PM, Brian Goetz wrote:
> This problem is not specific to lambda, of course; we have this problem
> with regular methods too.

Is not JEP 118 solve that issue ?
http://openjdk.java.net/jeps/118

Rémi

>
> On 1/7/2013 11:51 AM, Beran, Sam E wrote:
>> 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: https://gist.github.com/4277292#file-metafunction
>>
>> 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.
>>
>> Thanks,
>> Sam
>>



More information about the lambda-dev mailing list