Primitive streams and optional (original) (raw)

Tim Peierls tim at peierls.net
Sun Nov 25 09:01:21 PST 2012


On Sun, Nov 25, 2012 at 10:42 AM, Remi Forax <forax at univ-mlv.fr> wrote:

On 11/25/2012 02:14 PM, Doug Lea wrote:

On 11/21/12 12:59, Brian Goetz wrote:

OK, I think we have all the options and combinations of options on the table.

A: OptionalInt min() B: int min(int defaultValue) C: int min() throws NSEE

I vote for renaming to make clearer that this is a reduction with a basis, and then providing two forms: int least(int ceiling); // return least value < ceiling, or ceiling if_ _none_ _int least(); // default ceiling == Integer.MAXVALUE_ _I prefer :_ _int least(IntSupplier supplier); // return least value < ceiling, or_ _suplier.supply() if none_ _int least(); // default supplier == () -> Integer.MAXVALUE it's not rare to have a default value that also requires computation and I don't want to compute it if I don't need it.

This would be more appealing with OptionalXxx, moving the Supplier argument away from the stream and onto the Optional object itself:

return s.least().or(() -> computeDefaultValue());

--tim



More information about the lambda-libs-spec-observers mailing list