@metreeca/pipe - v0.9.20
    Preparing search index...

    Function toMap

    • Creates a sink collecting items into a map using item values.

      Type Parameters

      • V

        The type of items in the stream

      • K

        The type of map keys

      Parameters

      • key: (item: V) => K | Promise<K>

        The function to extract the key from each item

      Returns Sink<V, ReadonlyMap<K, V>>

      A sink that collects items into a map with keys from the key selector and items as values

      await items([{ id: 1, name: "Alice" }, { id: 2, name: "Bob" }])(toMap(x => x.id));
      // Map(2) { 1 => { id: 1, name: "Alice" }, 2 => { id: 2, name: "Bob" } }
    • Creates a sink collecting items into a map using custom keys and values.

      Type Parameters

      • V

        The type of items in the stream

      • K

        The type of map keys

      • R

        The type of map values

      Parameters

      • key: (item: V) => K | Promise<K>

        The function to extract the key from each item

      • value: (item: V) => R | Promise<R>

        The function to transform each item into a map value

      Returns Sink<V, ReadonlyMap<K, R>>

      A sink that collects items into a map with keys and values from the selectors

      await items([{ id: 1, name: "Alice" }, { id: 2, name: "Bob" }])(toMap(x => x.id, x => x.name));
      // Map(2) { 1 => "Alice", 2 => "Bob" }