Skip to content

Commit

Permalink
feat: add right joins
Browse files Browse the repository at this point in the history
rob893 committed Sep 8, 2021
1 parent 9f9bbce commit 288ea17
Showing 2 changed files with 52 additions and 1 deletion.
52 changes: 51 additions & 1 deletion src/Enumerable.ts
Original file line number Diff line number Diff line change
@@ -68,7 +68,9 @@ import {
join,
groupJoin,
leftJoinHeterogeneous,
leftJoinHomogeneous
leftJoinHomogeneous,
rightJoinHeterogeneous,
rightJoinHomogeneous
} from '.';

export class Enumerable<TSource> implements Iterable<TSource> {
@@ -385,6 +387,54 @@ export class Enumerable<TSource> implements Iterable<TSource> {
return reverse(this);
}

/**
* Performs a right outer join on two heterogeneous sequences.
* @param second The second sequence of the join operation.
* @param firstKeySelector Function that projects the key given an element from first.
* @param secondKeySelector Function that projects the key given an element from second.
* @param secondSelector Function that projects the result given just an element from second where there is no corresponding element in first.
* @param bothSelector Function that projects the result given an element from first and an element from second that match on a common key.
* @param equalityComparer A function to compare keys.
* @returns A sequence containing results projected from a right outer join of the two input sequences.
*/
public rightJoinHeterogeneous<TSecond, TKey, TResult>(
second: Iterable<TSecond>,
firstKeySelector: (item: TSource) => TKey,
secondKeySelector: (item: TSecond) => TKey,
secondSelector: (item: TSecond) => TResult,
bothSelector: (a: TSource, b: TSecond) => TResult,
equalityComparer?: EqualityComparer<TKey>
): Enumerable<TResult> {
return rightJoinHeterogeneous(
this,
second,
firstKeySelector,
secondKeySelector,
secondSelector,
bothSelector,
equalityComparer
);
}

/**
* Performs a right outer join on two homogeneous sequences.
* @param second The second sequence of the join operation.
* @param keySelector Function that projects the key given an element of one of the sequences to join.
* @param secondSelector Function that projects the result given just an element from second where there is no corresponding element in first.
* @param bothSelector Function that projects the result given an element from first and an element from second that match on a common key.
* @param equalityComparer A function to compare keys.
* @returns A sequence containing results projected from a right outer join of the two input sequences.
*/
public rightJoinHomogeneous<TKey, TResult>(
second: Iterable<TSource>,
keySelector: (item: TSource) => TKey,
secondSelector: (item: TSource) => TResult,
bothSelector: (a: TSource, b: TSource) => TResult,
equalityComparer?: EqualityComparer<TKey>
): Enumerable<TResult> {
return rightJoinHomogeneous(this, second, keySelector, secondSelector, bothSelector, equalityComparer);
}

public select<TDestination>(exp: (item: TSource, index: number) => TDestination): Enumerable<TDestination> {
return select(this, exp);
}
1 change: 1 addition & 0 deletions src/functions/index.ts
Original file line number Diff line number Diff line change
@@ -35,6 +35,7 @@ export * from './quantile';
export * from './range';
export * from './repeat';
export * from './reverse';
export * from './rightJoin';
export * from './select';
export * from './sequenceEqual';
export * from './shuffle';

0 comments on commit 288ea17

Please sign in to comment.