• This creates a signal that will cycle through a source of values, returning the the start after each call of next.

    Type Parameters

    • T

    Parameters

    • sequence: ValueSource<ArrayLike<T> | Cursor<T>>

      The source of sequence values. Could be an ArrayLike object or a "Cursor" which is like an iterator, but with a reset method.

    • options: SequenceSignalOptions = {}

      Options for creating the sequence signal.

    Returns SequenceSignal<T>

    The sequence signal.

    const boolSeq = sequenceSignal([true, false]);
    console.log(boolSeq()) // true
    boolSeq.next();
    console.log(boolSeq()) // false
    boolSeq.next();
    console.log(boolSeq()) // true

    const lettersSeq = sequenceSignal('ABCDEFG');
    console.log(letterSeq()) // A;
    boolSeq.next(2);
    console.log(letterSeq()) // C;

    // pass a "Cursor" to generate a sequence.
    sequenceSignal((() => {
    let values = [1, 2];
    return {
    next: (relativeChange: number) => {
    for (let i = 0; i < relativeChange; i++) {
    values = [values[1], values[0] + values[1]];
    }
    for (let i = relativeChange; i < 0; i++) {
    values = [Math.max(1, values[1] - values[0]), Math.max(values[0], 2)];
    }
    return { hasValue: true, value: values[0] };
    },
    reset: () => values = [1, 2]
    };
    })());
    console.log(fibSeq()); // 1;
    fibSeq.next();
    console.log(fibSeq()); // 2;