stepByStep()

Performs a callback function with the ability to decide when to move to the next step of the range

Range.prototype.stepByStep()

The stepByStep() method performs a callback function with the ability to decide when to move to the next step of the range.

range.class.ts
public stepByStep(
  callbackFn: (value: Generator<number>, step: Step, max: Max) => void
): this {
  const t = this;
  callbackFn(
    (function* stepByStep(current = t.min - t.step): Generator<number> {
      while (current < t.max) {
        yield (current += t.step);
      }
    })(),
    t.step,
    t.max
  );
  return this;
}

Parameters

callbackFn: (value:Generator<number>, step:Step, max:Max) => void

A function that accepts up to three arguments. The value is a function generator that allows deciding when to move to the next step, step is the step, and max is the maximum of a specified Range object.

value:Generator<number> - Function generator allows deciding when to move to the next range step. step:Step - The step of a specified Range object. max:Max - The maximum range of a specified Range object.

Return type

Returns

The return value is the Range instance.

Example usage

// Example usage.
import { Range } from '@angular-package/range';

// Create new instance.
const range = new Range(4, 27, 1.5);

range.stepByStep((value) => {
  // Returns 4
  value.next().value;
  // Returns 5.5
  value.next().value;
  // Returns 7
  value.next().value;
  // Returns 8.5
  value.next().value;
  // Returns 10
  value.next().value;
  // Returns 11.5
  value.next().value;
  // Returns 13
  value.next().value;
});

Last updated