Note on java.util.functions
Klaus Malorny
Klaus.Malorny at knipp.de
Tue May 22 11:33:50 PDT 2012
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