Function rightJoinHeterogeneous

  • Performs a right outer join on two heterogeneous sequences.

    Example

    const right = 'right';
    const both = 'both';
    const missing = null;

    type Side = typeof right | typeof both;
    type Person = { name: string };
    type Pet = { name: string; owner: Person };

    const magnus: Person = { name: 'Magnus' };
    const terry: Person = { name: 'Terry' };
    const adam: Person = { name: 'Adam' };
    const john: Person = { name: 'John' };

    const barley: Pet = { name: 'Barley', owner: terry };
    const boots: Pet = { name: 'Boots', owner: terry };
    const whiskers: Pet = { name: 'Whiskers', owner: adam };
    const daisy: Pet = { name: 'Daisy', owner: magnus };
    const scratchy: Pet = { name: 'Scratchy', owner: { name: 'Bob' } };

    const people = from([magnus, terry, adam, john]);
    const pets = from([barley, boots, whiskers, daisy, scratchy]);

    const result = rightJoinHeterogeneous<Pet, Person, { side: Side; left: Person | null; right: Pet }>(
    people,
    pets,
    person => person,
    pet => pet.owner,
    pet => ({ side: right, left: missing, right: pet }),
    (person, pet) => ({ side: both, left: person, right: pet })
    )
    .toArray();

    expect(result).toEqual([
    { side: both, left: terry, right: barley },
    { side: both, left: terry, right: boots },
    { side: both, left: adam, right: whiskers },
    { side: both, left: magnus, right: daisy },
    { side: right, left: missing, right: scratchy } // Scratchy has an owner, Bob, but Bob is not in the calling collection, hence the 'missing'.
    ]);

    Typeparam

    TFirst The type of elements in the first sequence.

    Typeparam

    TSecond The type of elements in the second sequence.

    Typeparam

    TKey The type of the key returned by the key selector functions.

    Typeparam

    TResult The type of the result elements.

    Returns

    A sequence containing results projected from a right outer join of the two input sequences.

    Type Parameters

    • TFirst

    • TSecond

    • TKey

    • TResult

    Parameters

    • first: Iterable<TFirst>

      The first sequence of the join operation.

    • second: Iterable<TSecond>

      The second sequence of the join operation.

    • firstKeySelector: ((item: TFirst) => TKey)

      Function that projects the key given an element from first.

        • (item: TFirst): TKey
        • Parameters

          • item: TFirst

          Returns TKey

    • secondKeySelector: ((item: TSecond) => TKey)

      Function that projects the key given an element from second.

        • (item: TSecond): TKey
        • Parameters

          • item: TSecond

          Returns TKey

    • secondSelector: ((item: TSecond) => TResult)

      Function that projects the result given just an element from second where there is no corresponding element in first.

        • (item: TSecond): TResult
        • Parameters

          • item: TSecond

          Returns TResult

    • bothSelector: ((a: TFirst, b: TSecond) => TResult)

      Function that projects the result given an element from first and an element from second that match on a common key.

        • (a: TFirst, b: TSecond): TResult
        • Parameters

          • a: TFirst
          • b: TSecond

          Returns TResult

    • Optional equalityComparer: EqualityComparer<TKey>

      A function to compare keys.

    Returns IEnumerable<TResult>

Generated using TypeDoc