ts-iterable-functions
    Preparing search index...

    Function _join

    • Performs an inner join between the source iterable and the supplied sequence.

      Type Parameters

      • T

        Element type produced by the source iterable.

      • TInner

        Element type produced by the inner sequence.

      • TKey

        Key type returned by both key selector functions.

      • TOut

        Resulting element type produced by the selector.

      Parameters

      • src: Iterable<T>

        Source iterable providing the outer elements.

      • innerSeq: Iterable<TInner>

        Iterable providing the inner elements to match.

      • outerKeySelector: IndexedSelector<T, TKey>

        Selector extracting the key for each outer element.

      • innerKeySelector: IndexedSelector<TInner, TKey>

        Selector extracting the key for each inner element.

      • selector: (outer: T, inner: TInner) => TOut

        Projection producing the output value for every matching pair.

      • OptionalmapFactory: MapFactory<TKey>

        Optional factory supplying the map used to group inner elements.

      Returns Iterable<TOut>

      A deferred iterable of projected values for each matching key pair.

      Error Rethrows any error thrown by the selectors or mapFactory.

      const users = [
      { id: 1, name: "Ada" },
      { id: 2, name: "Grace" },
      ];
      const roles = [
      { userId: 1, role: "admin" },
      { userId: 1, role: "editor" },
      { userId: 3, role: "viewer" },
      ];
      const joined = [
      ..._join(
      users,
      roles,
      (user) => user.id,
      (role) => role.userId,
      (user, role) => ({ user: user.name, role: role.role })
      ),
      ];
      console.log(joined);
      // [{ user: "Ada", role: "admin" }, { user: "Ada", role: "editor" }]

      or using the curried version:

      const users = [
      { id: 1, name: "Ada" },
      { id: 2, name: "Grace" },
      ];
      const roles = [
      { userId: 1, role: "admin" },
      { userId: 1, role: "editor" },
      { userId: 3, role: "viewer" },
      ];
      const joined = [
      ...pipeInto(
      users,
      join(
      roles,
      (user) => user.id,
      (role) => role.userId,
      (user, role) => ({ user: user.name, role: role.role })
      )
      ),
      ];
      console.log(joined);
      // [{ user: "Ada", role: "admin" }, { user: "Ada", role: "editor" }]