@mirei/ts-collections
    Preparing search index...

    Function rightJoin

    • Produces a projection from the sequence and a second sequence by matching elements that share an identical join key. Inner elements with no match are included once with null as the outer value.

      Type Parameters

      • TElement

        Type of elements within the outer sequence.

      • TInner

        Type of elements within the inner sequence.

      • TKey

        Type of key produced by the key selectors.

      • TResult

        Type of element returned by resultSelector.

      Parameters

      • source: Iterable<TElement>

        The outer sequence.

      • innerEnumerable: Iterable<TInner>

        Sequence whose elements are joined with the outer sequence.

      • outerKeySelector: Selector<TElement, TKey>

        Selector that extracts the join key from each outer element.

      • innerKeySelector: Selector<TInner, TKey>

        Selector that extracts the join key from each inner element.

      • resultSelector: JoinSelector<TElement | null, TInner, TResult>

        Projection that combines an outer element with a matching inner element. When no match exists, null is supplied as the outer value.

      • OptionalkeyComparator: EqualityComparator<TKey, TKey>

        Optional equality comparator used to match keys. Defaults to the library's standard equality comparison when omitted.

      Returns IEnumerable<TResult>

      A sequence generated by applying resultSelector to each matching pair (and unmatched inner elements).

      The outer sequence is fully enumerated to build an in-memory lookup before inner elements are processed. The inner sequence is then enumerated lazily and its original ordering is preserved. This is a right outer join.

      const categories = [
      { id: 1, name: 'Fruit' },
      { id: 2, name: 'Vegetable' },
      ];
      const products = [
      { name: 'Apple', categoryId: 1 },
      { name: 'Banana', categoryId: 1 },
      { name: 'Unknown', categoryId: 3 },
      ];

      const joined = rightJoin(
      categories,
      products,
      c => c.id,
      p => p.categoryId,
      (c, p) => ({ category: c?.name ?? null, product: p.name })
      ).toArray();

      console.log(joined);
      // [
      // { category: 'Fruit', product: 'Apple' },
      // { category: 'Fruit', product: 'Banana' },
      // { category: null, product: 'Unknown' }
      // ]