-
Notifications
You must be signed in to change notification settings - Fork 2
/
selectMany.ts
30 lines (23 loc) · 853 Bytes
/
selectMany.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
import { IIterator } from "../intefaces/iterator.interface";
import { SelectClause } from "./select";
import { BaseIterator } from "../implements/baseIterator";
export class SelectManyClause<T> extends BaseIterator<T> implements IIterator<T> {
_iterator: (item: T, index?: number) => any;
execute(source: T[]): any[] {
if (!source) return null;
let _result = new SelectClause(this._iterator).execute(source);
if (!_result) return null;
let _tmp = [];
for (let i = 0, li = _result.length; i < li; i++) {
if (Array.isArray(_result[i]))
_tmp = _tmp.concat(_result[i])
else
_tmp.push(_result[i])
}
return _tmp;
}
constructor(func: (item: T, index?: number) => any) {
super();
this._iterator = func;
}
}