-
Notifications
You must be signed in to change notification settings - Fork 0
/
join.ts
31 lines (30 loc) · 894 Bytes
/
join.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import { pipeInto as pp, deferP0 } from "ts-functional-pipe";
import { IndexedSelector } from "../types/IndexedSelector";
import { MapFactory } from "../types/MapFactory";
import { flatMap } from "./flatMap";
import { groupJoin } from "./groupJoin";
import { _map } from "./map";
export function _join<T, TInner, TKey, TOut>(
src: Iterable<T>,
innerSeq: Iterable<TInner>,
outerKeySelector: IndexedSelector<T, TKey>,
innerKeySelector: IndexedSelector<TInner, TKey>,
selector: (outer: T, inner: TInner) => TOut,
mapFactory?: MapFactory<TKey>
): Iterable<TOut> {
return pp(
src,
groupJoin(
innerSeq,
outerKeySelector,
innerKeySelector,
(outer, innerSeq) => ({
outer,
innerSeq,
}),
mapFactory
),
flatMap(({ outer, innerSeq }) => _map(innerSeq, (i) => selector(outer, i)))
);
}
export const join = deferP0(_join);