ints(), longs(), doubles() <was> Re: Ranges

John Rose john.r.rose at oracle.com
Fri May 3 20:30:58 PDT 2013


On May 3, 2013, at 6:45 PM, Howard Lovatt <howard.lovatt at gmail.com> wrote:

> I write numerical code and find something like:
> 
>  from(start).to(exclusiveEnd).step(step).stream()...

Nice, a fluent API for ranges, with a real user testimonial!

It's interesting that you don't cite an inclusive version of to() in this API.  Do you use the API mainly for array (or list or vector) index generation, or are there use cases where you are working with an abstract number line?

In practice, for what purpose do you use the overloadings of "step"?  Is its presence for Fortran-like access patterns, or is it mainly a just matter of completing the API?

In the number-line case, people sometimes seem to need inclusive end points.  (I say "seem" since the end points are always special.)  For approximate integrations, you might want "tripCount" or "meshSize" even more than "step".

Inclusive end points are mandatory in the case of small-cardinality enumerated types or chars, since "the last code point plus one" doesn't mean anything.  For those use cases, step usually doesn't matter.

HTH

— John


More information about the lambda-dev mailing list