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

    Function take

    • Creates a task truncating the feed to a prefix.

      Items are emitted in source order and the feed ends as soon as the quota is met, leaving the rest of the source unconsumed.

      Note

      • Incremental: items are emitted as they are drawn and the reported feed ends at n items, whatever the feed drawn from, which is the standard way to bound an infinite feed.
      • Streaming: items are emitted one at a time, none retained.
      • Stateful: the quota is counted over the items drawn, so a task invoked per nested feed or per run grants its quota to each rather than to the feed as a whole.

      Type Parameters

      • V

        The type of items in the feed

      Parameters

      • n: number

        The maximum number of leading items to emit; values less than 1 empty the feed

      Returns Task<V>

      A task yielding at most the first n items

      TypeError If n is not an integer

      await pipe(
      (items([1, 2, 3, 4, 5]))
      (take(3))
      (toArray())
      ); // [1, 2, 3]