@nestia/e2e 0.1.1 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/ArrayUtil.ts CHANGED
@@ -1,87 +1,87 @@
1
- /**
2
- * Utility functions for arrays.
3
- *
4
- * @author Jeongho Nam - https://github.com/samchon
5
- */
6
- export namespace ArrayUtil {
7
- export async function asyncFilter<Input>(
8
- elements: readonly Input[],
9
- pred: (
10
- elem: Input,
11
- index: number,
12
- array: readonly Input[],
13
- ) => Promise<boolean>,
14
- ): Promise<Input[]> {
15
- const ret: Input[] = [];
16
- await asyncForEach(elements, async (elem, index, array) => {
17
- const flag: boolean = await pred(elem, index, array);
18
- if (flag === true) ret.push(elem);
19
- });
20
- return ret;
21
- }
22
-
23
- export async function asyncForEach<Input>(
24
- elements: readonly Input[],
25
- closure: (
26
- elem: Input,
27
- index: number,
28
- array: readonly Input[],
29
- ) => Promise<any>,
30
- ): Promise<void> {
31
- await asyncRepeat(elements.length, (index) =>
32
- closure(elements[index], index, elements),
33
- );
34
- }
35
-
36
- export async function asyncMap<Input, Output>(
37
- elements: readonly Input[],
38
- closure: (
39
- elem: Input,
40
- index: number,
41
- array: readonly Input[],
42
- ) => Promise<Output>,
43
- ): Promise<Output[]> {
44
- const ret: Output[] = [];
45
- await asyncForEach(elements, async (elem, index, array) => {
46
- const output: Output = await closure(elem, index, array);
47
- ret.push(output);
48
- });
49
- return ret;
50
- }
51
-
52
- export async function asyncRepeat<T>(
53
- count: number,
54
- closure: (index: number) => Promise<T>,
55
- ): Promise<T[]> {
56
- const indexes: number[] = new Array(count)
57
- .fill(1)
58
- .map((_, index) => index);
59
-
60
- const output: T[] = [];
61
- for (const index of indexes) output.push(await closure(index));
62
-
63
- return output;
64
- }
65
-
66
- export function has<T>(
67
- elements: readonly T[],
68
- pred: (elem: T) => boolean,
69
- ): boolean {
70
- return elements.find(pred) !== undefined;
71
- }
72
-
73
- export function repeat<T>(
74
- count: number,
75
- closure: (index: number) => T,
76
- ): T[] {
77
- return new Array(count).fill("").map((_, index) => closure(index));
78
- }
79
-
80
- export function last<T>(array: T[]): T {
81
- return array[array.length - 1];
82
- }
83
-
84
- export function flat<T>(matrix: T[][]): T[] {
85
- return ([] as T[]).concat(...matrix);
86
- }
87
- }
1
+ /**
2
+ * Utility functions for arrays.
3
+ *
4
+ * @author Jeongho Nam - https://github.com/samchon
5
+ */
6
+ export namespace ArrayUtil {
7
+ export async function asyncFilter<Input>(
8
+ elements: readonly Input[],
9
+ pred: (
10
+ elem: Input,
11
+ index: number,
12
+ array: readonly Input[],
13
+ ) => Promise<boolean>,
14
+ ): Promise<Input[]> {
15
+ const ret: Input[] = [];
16
+ await asyncForEach(elements, async (elem, index, array) => {
17
+ const flag: boolean = await pred(elem, index, array);
18
+ if (flag === true) ret.push(elem);
19
+ });
20
+ return ret;
21
+ }
22
+
23
+ export async function asyncForEach<Input>(
24
+ elements: readonly Input[],
25
+ closure: (
26
+ elem: Input,
27
+ index: number,
28
+ array: readonly Input[],
29
+ ) => Promise<any>,
30
+ ): Promise<void> {
31
+ await asyncRepeat(elements.length, (index) =>
32
+ closure(elements[index], index, elements),
33
+ );
34
+ }
35
+
36
+ export async function asyncMap<Input, Output>(
37
+ elements: readonly Input[],
38
+ closure: (
39
+ elem: Input,
40
+ index: number,
41
+ array: readonly Input[],
42
+ ) => Promise<Output>,
43
+ ): Promise<Output[]> {
44
+ const ret: Output[] = [];
45
+ await asyncForEach(elements, async (elem, index, array) => {
46
+ const output: Output = await closure(elem, index, array);
47
+ ret.push(output);
48
+ });
49
+ return ret;
50
+ }
51
+
52
+ export async function asyncRepeat<T>(
53
+ count: number,
54
+ closure: (index: number) => Promise<T>,
55
+ ): Promise<T[]> {
56
+ const indexes: number[] = new Array(count)
57
+ .fill(1)
58
+ .map((_, index) => index);
59
+
60
+ const output: T[] = [];
61
+ for (const index of indexes) output.push(await closure(index));
62
+
63
+ return output;
64
+ }
65
+
66
+ export function has<T>(
67
+ elements: readonly T[],
68
+ pred: (elem: T) => boolean,
69
+ ): boolean {
70
+ return elements.find(pred) !== undefined;
71
+ }
72
+
73
+ export function repeat<T>(
74
+ count: number,
75
+ closure: (index: number) => T,
76
+ ): T[] {
77
+ return new Array(count).fill("").map((_, index) => closure(index));
78
+ }
79
+
80
+ export function last<T>(array: T[]): T {
81
+ return array[array.length - 1];
82
+ }
83
+
84
+ export function flat<T>(matrix: T[][]): T[] {
85
+ return ([] as T[]).concat(...matrix);
86
+ }
87
+ }