ixfx
    Preparing search index...

    Function until

    Yields all items in the input array for as long as predicate returns true.

    predicate yields arrays of [stop:boolean, acc:A]. The first value is true when the iteration should stop, and the acc is the accumulated value. This allows until to be used to carry over some state from item to item.

    const v = [...until([1,2,3,4,5], v => v === 3];
    // [ 1, 2 ]
    // Stop when accumulated value reaches 6
    const v = Arrays.until[1,2,3,4,5], (v, acc) => [acc >= 7, v+acc], 0);
    // [1, 2, 3]
    • Yields all items in the input array, stopping when predicate returns true.

      Type Parameters

      • V

      Parameters

      • data: readonly V[] | V[]
      • predicate: (v: V) => boolean

      Returns Generator<V>

      const data = [ 1, 2, 3, 4, 5 ];
      until(data, v => v === 3)
      // [ 1, 2 ]
    • Yields all items in the input array, stopping when predicate returns true. This version allows a value to be 'accumulated' somehow

      Type Parameters

      • V
      • A

      Parameters

      • data: readonly V[] | V[]
      • predicate: (v: V, accumulator: A) => readonly [boolean, A]
      • initial: A

      Returns Generator<V>

      const data = [ 1, 2, 3, 4, 5 ];
      until(data, (v, accumulated) => [accumulated >= 6, accumulated + v ]);
      // [ 1, 2, 3 ]