RFR : JDK-8001642 : Add Optional<T>, OptionalDouble, OptionalInt, OptionalLong
dl at cs.oswego.edu
Fri Mar 15 08:04:28 PDT 2013
On 03/15/13 09:46, Brian Goetz wrote:
> Wouldn't the minimal change NOT have a predicate, to match the existing form of
> Optional<T> findFirst()
> T findFirst(T orElse)
Yes and no. The only way to get non-optional-bearing
result for search would otherwise be s.filter(pred).findAny(),
which entails buffering of stuff you will throw away.
This is also the reason only adding why findAny(pred) (not findDirst)
is defensible: the alternative is of most interest to the sort of
person who want to avoid that Optional too.
> On 3/15/2013 7:31 AM, Doug Lea wrote:
>> On 03/15/13 06:26, Joe Bowbeer wrote:
>>> I think your point that Optional and non-Optional forms of reduce are
>>> provided is significant.
>>> I noticed that your proposed versions of findFirst and findAny have a
>>> argument, but the Optional forms do not:
>>> T findFirst(Predicate<? super T> predicate, T ifNone);
>>> Why is this?
>> It's in the spirit of proposing a minimal change. The predicate
>> form suffices for all Optional-avoiding search stuff. To reduce
>> impact by another 50%, it would suffice to ONLY include the "any" form.
>> T findAny(Predicate<? super T> predicate, T ifNone);
More information about the lambda-libs-spec-experts