ts-data-forge
    Preparing search index...

    Function range

    • Generates a sequence of numbers within a specified range using a generator function.

      This function creates a generator that yields numbers from start (inclusive) to end (exclusive) with the specified step increment/decrement. The function implements the JavaScript iterator protocol, making it compatible with for-of loops, spread operator, Array.from(), and other iterator consumers.

      The function has two overloaded signatures:

      1. For non-negative ranges: accepts SafeUint parameters and optional positive step
      2. For general ranges: accepts SafeInt parameters and optional non-zero step

      Generator Behavior:

      • Yields values lazily (computed on-demand)
      • Returns void when iteration completes
      • Does not accept sent values (next parameter is ignored)
      • Automatically handles direction based on step sign and start/end relationship

      Step Parameter Behavior:

      • Positive step: iterates from start toward end (start < end expected)
      • Negative step: iterates from start toward end (start > end expected)
      • Zero step: not allowed (NonZeroSafeInt constraint)
      • Default step: 1 (positive direction)

      Edge Cases:

      • When start equals end: yields no values (empty sequence)
      • When step direction conflicts with start/end relationship: yields no values
      • All parameters must be safe integers (within JavaScript's safe integer range)

      Parameters

      • end: WithSmallInt<SafeUint, 512>

        The end number of the sequence (exclusive). Must be a safe integer.

      Returns Generator<SafeUint, void, unknown>

      A Generator object that yields safe integers in the specified range.

      const zeroToThree = Array.from(range(0, 3));
      const threeToZero = Array.from(range(3, 0, -1));
      const defaultEnd = Array.from(range(4));

      assert.deepStrictEqual(zeroToThree, [0, 1, 2]);
      assert.deepStrictEqual(threeToZero, [3, 2, 1]);
      assert.deepStrictEqual(defaultEnd, [0, 1, 2, 3]);
    • Generates a sequence of numbers within a specified range using a generator function.

      This function creates a generator that yields numbers from start (inclusive) to end (exclusive) with the specified step increment/decrement. The function implements the JavaScript iterator protocol, making it compatible with for-of loops, spread operator, Array.from(), and other iterator consumers.

      The function has two overloaded signatures:

      1. For non-negative ranges: accepts SafeUint parameters and optional positive step
      2. For general ranges: accepts SafeInt parameters and optional non-zero step

      Generator Behavior:

      • Yields values lazily (computed on-demand)
      • Returns void when iteration completes
      • Does not accept sent values (next parameter is ignored)
      • Automatically handles direction based on step sign and start/end relationship

      Step Parameter Behavior:

      • Positive step: iterates from start toward end (start < end expected)
      • Negative step: iterates from start toward end (start > end expected)
      • Zero step: not allowed (NonZeroSafeInt constraint)
      • Default step: 1 (positive direction)

      Edge Cases:

      • When start equals end: yields no values (empty sequence)
      • When step direction conflicts with start/end relationship: yields no values
      • All parameters must be safe integers (within JavaScript's safe integer range)

      Parameters

      • start: WithSmallInt<SafeUint, 512>

        The starting number of the sequence (inclusive). Must be a safe integer.

      • end: WithSmallInt<SafeUint, 512>

        The end number of the sequence (exclusive). Must be a safe integer.

      • Optionalstep: WithSmallInt<PositiveSafeInt, 512>

        The increment or decrement value. Defaults to 1. Must be non-zero safe integer.

      Returns Generator<SafeUint, void, unknown>

      A Generator object that yields safe integers in the specified range.

      const zeroToThree = Array.from(range(0, 3));
      const threeToZero = Array.from(range(3, 0, -1));
      const defaultEnd = Array.from(range(4));

      assert.deepStrictEqual(zeroToThree, [0, 1, 2]);
      assert.deepStrictEqual(threeToZero, [3, 2, 1]);
      assert.deepStrictEqual(defaultEnd, [0, 1, 2, 3]);
    • Generates a sequence of numbers within a specified range using a generator function.

      This function creates a generator that yields numbers from start (inclusive) to end (exclusive) with the specified step increment/decrement. The function implements the JavaScript iterator protocol, making it compatible with for-of loops, spread operator, Array.from(), and other iterator consumers.

      The function has two overloaded signatures:

      1. For non-negative ranges: accepts SafeUint parameters and optional positive step
      2. For general ranges: accepts SafeInt parameters and optional non-zero step

      Generator Behavior:

      • Yields values lazily (computed on-demand)
      • Returns void when iteration completes
      • Does not accept sent values (next parameter is ignored)
      • Automatically handles direction based on step sign and start/end relationship

      Step Parameter Behavior:

      • Positive step: iterates from start toward end (start < end expected)
      • Negative step: iterates from start toward end (start > end expected)
      • Zero step: not allowed (NonZeroSafeInt constraint)
      • Default step: 1 (positive direction)

      Edge Cases:

      • When start equals end: yields no values (empty sequence)
      • When step direction conflicts with start/end relationship: yields no values
      • All parameters must be safe integers (within JavaScript's safe integer range)

      Parameters

      • start: WithSmallInt<SafeInt, 512>

        The starting number of the sequence (inclusive). Must be a safe integer.

      • end: WithSmallInt<SafeInt, 512>

        The end number of the sequence (exclusive). Must be a safe integer.

      • Optionalstep: WithSmallInt<NonZeroSafeInt, 512>

        The increment or decrement value. Defaults to 1. Must be non-zero safe integer.

      Returns Generator<SafeInt, void, unknown>

      A Generator object that yields safe integers in the specified range.

      const zeroToThree = Array.from(range(0, 3));
      const threeToZero = Array.from(range(3, 0, -1));
      const defaultEnd = Array.from(range(4));

      assert.deepStrictEqual(zeroToThree, [0, 1, 2]);
      assert.deepStrictEqual(threeToZero, [3, 2, 1]);
      assert.deepStrictEqual(defaultEnd, [0, 1, 2, 3]);