Function until

  • Yields all items in data 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.

    Type Parameters

    • V
    • A

    Parameters

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

          • v: V
          • accumulator: A

          Returns readonly [boolean, A]

    • initial: A

    Returns Generator<V>

    const v = [...until([1,2,3,4,5], v => [v === 3, 0])];
    // [ 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]