Function count

  • Yields amount integers, counting by one from zero. If a negative amount is used, count decreases. If offset is provided, this is added to the return result.

    Parameters

    • amount: number

      Number of integers to yield

    • offset: number = 0

      Added to result

    Returns Generator<number, void, void>

    const a = [...count(5)]; // Yields five numbers: [0,1,2,3,4]
    const b = [...count(-5)]; // Yields five numbers: [0,-1,-2,-3,-4]
    for (const v of count(5, 5)) {
    // Yields: 5, 6, 7, 8, 9
    }
    const c = [...count(5,1)]; // Yields [1,2,3,4,5]
    // Prints `Hi` 5x
    forEach(count(5), () => // do something);

    If you want to accumulate return values, consider using Flow.repeat.

    import { interval } from 'https://unpkg.com/ixfx/dist/flow.js'
    import { count } from 'https://unpkg.com/ixfx/dist/numbers.js'
    const counter = count(10);
    for await (const v of interval(counter, { fixedIntervalMs: 100 })) {
    // Do something
    }