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

Howard Lovatt howard.lovatt at gmail.com
Sun May 5 13:53:01 PDT 2013


PS if I have a repeated loop range, common in numerical code, I save the Range, e.g.:

  Range inner = from(1).to(size -1);
  double[] a = new double[size];
  a[0] = ...;
  inner.stream().parallel().forEach((i) -> a[i] = ...);
  a[size -1] = ...;
  double[] b = new double[size];
  b[0] = ...a[0]...a[1]...;
  inner.stream().parallel().forEach((i) -> b[i] = ...a[i - 1]...a[i]...a[i + 1]...);
  b[size - 1] = ...a[size - 2]...a[size - 1]...;

Much lake shapes are used in ZPL.

Sent from my iPad

On 04/05/2013, at 11:36 PM, Howard Lovatt <howard.lovatt at gmail.com> wrote:

> Yes I use it to iterate over indexes mainly; as a direct replacement for a for loop, with the body of the loop as the argument to forEach.
> 
> If you need an inclusive range then you can use the whileTrue form with (i) -> i <= inclusiveEnd; provided inclusiveEnd isn't MAX_VAL, in which case && i >= from also needed. 
> 
> For reverse loops I do:
> 
>   from(array.length - 1).whileTrue((i) -> i >= 0).step(-1).stream()...
> 
> IE it is up to the programmer to get the limits right and consistent with step, I don't check the values because I don't know them for the generalised forms of to (whileTrue) and step (with lambda argument). 
> 
>  -- Howard. 
> 
> Sent from my iPad
> 
> On 04/05/2013, at 1:42 PM, John Rose <john.r.rose at oracle.com> wrote:
> 
>> On May 3, 2013, at 8:30 PM, John Rose <john.r.rose at oracle.com> wrote:
>> 
>>> Do you use the API mainly for array (or list or vector) index generation
>> 
>> P.S. Also, what does it look like when you need to iterate over an array in reverse order?


More information about the lambda-dev mailing list