@metreeca/flow - v0.9.21
    Preparing search index...

    Function iterate

    • Creates a feed from repeated calls to a generator function.

      The generator is called on demand, once the value it returned last has been consumed, and the feed ends as soon as a call returns undefined. Every other value is contributed as a single item, whatever its shape and without being expanded further, so arrays and iterables are carried whole and falsy values are preserved. A promised value is awaited before being contributed, so cursors, queues and any other source producing one value at a time are driven directly by the feed.

      Generators that never run dry produce an infinite feed, to be bounded downstream by a task such as take or by a sink deciding its outcome early.

      Type Parameters

      • V

        The type of values contributed to the feed

      Parameters

      • generator: () => Awaitable<V | undefined>

        The function called repeatedly to produce the next value; an undefined result ends the feed

      Returns Feed<V>

      A feed yielding the values returned by successive generator calls

      await pipe(
      (iterate(() => Math.random()))
      (take(3))
      (toArray())
      ); // [0.123, 0.456, 0.789]

      feed to open a feed from a source expanded according to its shape