Expected distribution of lambda sizes (Re: Syntax poll, take 2)

Sam Pullara sam at sampullara.com
Tue Jun 14 11:26:43 PDT 2011


Actually, one of the nice things about lambdas is now I will have a helper method something like (not tested):

public static <T,R> R n(T t, Function<T, R> f) {
   return t == null ? null : f.apply(t));
}

students.filter(s -> "Smith".equals(n(o, o->o.getName())));

Roughly equivalent to the .? type operators. Or:

students.filter(s -> "Smith".equals(n(o, Student#getName)));

Sam

On Jun 14, 2011, at 7:52 AM, Neal Gafter wrote:

> On Tue, Jun 14, 2011 at 3:18 AM, Stephen Colebourne <scolebourne at joda.org>wrote:
> 
>> Thus the example (adjusted to make the point) above in typical java might
>> be:
>> 
>> students.filter(#{student -> if (student == null ||
>> student.getName() == null) {return false;} else {return
>> student.getName().equals("Smith");}});
>> 
>> or formatted more typically:
>> 
>> students.filter(#{student ->
>>   if (student == null || student.getName() == null) {
>>     return false;
>>   } else {
>>     return student.getName().equals("Smith");
>>   }
>> });
>> 
> 
> students.filter(s => s!=null && "Smith".equals(s.getName()))
> 



More information about the lambda-dev mailing list