-
Notifications
You must be signed in to change notification settings - Fork 2
/
groupJoin.ts
38 lines (25 loc) 路 1.05 KB
/
groupJoin.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
32
33
34
35
36
37
38
import { IIterator } from "../intefaces/iterator.interface";
import { SelectClause } from "./select";
import { JoinClause } from "./join";
import { GroupByClause } from "./groupBy";
import { BaseIterator } from "../implements/baseIterator";
export class GroupJoinClause<T, S> extends BaseIterator<T> implements IIterator<T> {
nextSource: any[];
_joinIterator: (aEntity: T, bEntity: S) => boolean;
_groupIterator: (entity: { x: T; y: S; }) => any;
execute(source: T[]): T[] | any[] {
if (!source) return null;
let _result = new JoinClause(this.nextSource, this._joinIterator).execute(source);
_result = new GroupByClause(this._groupIterator).execute(_result as { x: T; y: S; }[]);
return _result;
}
constructor(
anotherSource: S[],
joinIterator: (aEntity: T, bEntity: S) => boolean,
groupIterator: (entity: { x: T; y: S; }) => any) {
super();
this._joinIterator = joinIterator;
this._groupIterator = groupIterator;
this.nextSource = anotherSource;
}
}