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

    Function trim

    Creates a task dropping undefined items, with or without a task reporting the items to trim, or opens a feed carrying the defined items of another feed.

    • Creates a task dropping undefined items from a feed.

      Items are emitted in source order; undefined items are dropped wherever they occur, not only at the ends of the feed, while null and other falsy values are retained.

      Note

      • Incremental: items are emitted as they are drawn, so the reported feed runs dry as the feed drawn from does.
      • Streaming: items are tested one at a time, none retained.
      • Stateless: every item is tested on its own, so the outcome is unaffected by how the feed is split across nested feeds or runs.

      Type Parameters

      • V

        The type of the defined items in the feed

      Returns Task<Optional<V>, V>

      A task yielding the defined items of the feed in source order

      await pipe(
      (items([undefined, 1, undefined, 2]))
      (trim())
      (toArray())
      ); // [1, 2]
    • Creates a task dropping the undefined items another task reports.

      Maps and drops items in a single stage: wrapping a mapper that returns undefined for the items to discard keeps the others as mapped. Items are emitted in the order task reports them; undefined items are dropped wherever they occur, while null and other falsy values are retained.

      Note

      • Incremental: items are emitted as task reports them, so the reported feed runs dry as the source and task do.
      • Streaming: items are tested one at a time, none retained, whatever task holds.
      • Stateless: every item is tested on its own, whatever task carries across the items it draws.

      Type Parameters

      • V

        The type of items drawn from the feed

      • R

        The type of the defined items task reports

      Parameters

      • task: Task<V, Optional<R>> & { "[asyncIterator]"?: undefined }

        The task reporting the items to trim

      Returns Task<V, R>

      A task yielding the defined items task reports, in the order it reports them

      await pipe(
      (items([1, 2, 3, 4]))
      (trim(map(n => n%2 ? n*10 : undefined)))
      (toArray())
      ); // [10, 30]
    • Opens a feed carrying the defined items of another feed.

      Trims a feed in place, without routing it through a pipe: trim(feed) carries the same items as feed(trim()). Items are emitted in the order feed carries them; undefined items are dropped wherever they occur, while null and other falsy values are retained.

      Note

      • Incremental: items are emitted as they are drawn, so the opened feed runs dry as feed does.
      • Streaming: items are tested one at a time, none retained.
      • Stateless: every item is tested on its own.

      Type Parameters

      • V

        The type of the defined items in the feed

      Parameters

      • feed: Feed<Optional<V>>

        The feed carrying the items to trim

      Returns Feed<V>

      A feed carrying the defined items of feed in source order

      await trim(items([undefined, 1, undefined, 2]))(toArray());  // [1, 2]