Note on java.util.functions

Brian Goetz brian.goetz at oracle.com
Tue May 22 11:45:45 PDT 2012


Yes, naming is still up in the air.  First nailing down semantics...

On 5/22/2012 2:33 PM, Klaus Malorny wrote:
> On 22/05/12 19:05, Brian Goetz wrote:
>>
>> Summary:
>>
>> getFirst -- find the first element of the stream in encounter order.  If
>> none is available, return (non-exceptional) indication of same.
>>
>> getOnly -- get the sole element of the stream; throw an exception if the
>> stream has zero elements or more than one element.  This allows you to
>> enforce a programmatic invariant at the same time as computing the answer.
>>
>> getAny -- find any element of the stream.  (For sequential streams, this
>> is likely to be identical to getFirst.)
>>
>> Any of these can be parallelized, to varying benefit, on finite streams.
>>     The one that shows the most parallel benefit is likely to be getAny,
>> though for streams involving highly selective filters or expensive
>> per-element computation, getFirst/getOnly may well show some speedup.
>>
>
> Hi Brian,
>
> please feel free to ignore, but I as a non-native speaker feel a bit lost about
> the semantics when I read the method name "getOnly". Have you considered an
> alternative name, for example "getSingle"?
>
> Regards,
>
> Klaus
>
>


More information about the lambda-dev mailing list