Nulls
Brian Goetz
brian.goetz at oracle.com
Sat Sep 22 11:00:43 PDT 2012
> I like these rules. The default-bearing version(s) can be emulated with
> the Option version with an additional Option2Default transform stage, so
> I would like to avoid the default-bearing version(s) if we can get away
> with it.
Right. We can factor out the default-injection by having an ifEmpty op:
list.filter(...)
.ifEmpty(defaultValue)
.optionBearingOp();
Not a big deal currently as we have relatively few Option-bearing ops,
but probably better to factor these out rather than ad-hoc fusing.
Similarly, we can have a filterNulls() op if users want the first
non-null value:
list.blah(...)
.filterNulls()
.findFirst();
(For stream sources where we *know* there are no nulls, such as
TreeSet.keys(), the cost of the filterNulls() is O(1) since it can be
optimized out of existence when we build the chain.)
More information about the lambda-libs-spec-experts
mailing list