-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
146 lines (138 loc) · 4.38 KB
/
index.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
import { map, curry } from 'ramda'
/**
* Performs left-to-right function composition and automatically lifts the initial value to a promise.
*/
function pipeAsync<A, B, C>(
ab: (a: A) => B | Promise<B>,
): (a: A) => Promise<B>;
function pipeAsync<A, B, C>(
ab: (a: A) => B | Promise<B>,
bc: (b: B) => C | Promise<C>,
): (a: A) => Promise<C>;
function pipeAsync<A, B, C, D>(
ab: (a: A) => B | Promise<B>,
bc: (b: B) => C | Promise<C>,
cd: (c: C) => D | Promise<D>,
): (a: A) => Promise<D>;
function pipeAsync<A, B, C, D, E>(
ab: (a: A) => B | Promise<B>,
bc: (b: B) => C | Promise<C>,
cd: (c: C) => D | Promise<D>,
de: (d: D) => E | Promise<E>,
): (a: A) => Promise<E>;
function pipeAsync<A, B, C, D, E, F>(
ab: (a: A) => B | Promise<B>,
bc: (b: B) => C | Promise<C>,
cd: (c: C) => D | Promise<D>,
de: (d: D) => E | Promise<E>,
ef: (e: E) => F | Promise<F>,
): (a: A) => Promise<F>;
function pipeAsync<A, B, C, D, E, F, G>(
ab: (a: A) => B | Promise<B>,
bc: (b: B) => C | Promise<C>,
cd: (c: C) => D | Promise<D>,
de: (d: D) => E | Promise<E>,
ef: (e: E) => F | Promise<F>,
fg: (f: F) => G | Promise<G>,
): (a: A) => Promise<G>;
function pipeAsync<A, B, C, D, E, F, G, H>(
ab: (a: A) => B | Promise<B>,
bc: (b: B) => C | Promise<C>,
cd: (c: C) => D | Promise<D>,
de: (d: D) => E | Promise<E>,
ef: (e: E) => F | Promise<F>,
fg: (f: F) => G | Promise<G>,
gh: (g: G) => H | Promise<H>,
): (a: A) => Promise<H>;
function pipeAsync<A, B, C, D, E, F, G, H, I>(
ab: (a: A) => B | Promise<B>,
bc: (b: B) => C | Promise<C>,
cd: (c: C) => D | Promise<D>,
de: (d: D) => E | Promise<E>,
ef: (e: E) => F | Promise<F>,
fg: (f: F) => G | Promise<G>,
gh: (g: G) => H | Promise<H>,
hi: (h: H) => I | Promise<I>,
): (a: A) => Promise<I>;
function pipeAsync<A, B, C, D, E, F, G, H, I, J>(
ab: (a: A) => B | Promise<B>,
bc: (b: B) => C | Promise<C>,
cd: (c: C) => D | Promise<D>,
de: (d: D) => E | Promise<E>,
ef: (e: E) => F | Promise<F>,
fg: (f: F) => G | Promise<G>,
gh: (g: G) => H | Promise<H>,
hi: (h: H) => I | Promise<I>,
ij: (i: I) => J | Promise<J>,
): (a: A) => Promise<J>;
function pipeAsync<A, B, C, D, E, F, G, H, I, J, K>(
ab: (a: A) => B | Promise<B>,
bc: (b: B) => C | Promise<C>,
cd: (c: C) => D | Promise<D>,
de: (d: D) => E | Promise<E>,
ef: (e: E) => F | Promise<F>,
fg: (f: F) => G | Promise<G>,
gh: (g: G) => H | Promise<H>,
hi: (h: H) => I | Promise<I>,
ij: (i: I) => J | Promise<J>,
jk: (j: J) => K | Promise<K>,
): (a: A) => Promise<K>;
function pipeAsync<A, B, C, D, E, F, G, H, I, J, K, M>(
ab: (a: A) => B | Promise<B>,
bc: (b: B) => C | Promise<C>,
cd: (c: C) => D | Promise<D>,
de: (d: D) => E | Promise<E>,
ef: (e: E) => F | Promise<F>,
fg: (f: F) => G | Promise<G>,
gh: (g: G) => H | Promise<H>,
hi: (h: H) => I | Promise<I>,
ij: (i: I) => J | Promise<J>,
jk: (j: J) => K | Promise<K>,
km: (k: K) => M | Promise<M>,
): (a: A) => Promise<M>;
function pipeAsync<A, B, C, D, E, F, G, H, I, J, K, M, N>(
ab: (a: A) => B | Promise<B>,
bc: (b: B) => C | Promise<C>,
cd: (c: C) => D | Promise<D>,
de: (d: D) => E | Promise<E>,
ef: (e: E) => F | Promise<F>,
fg: (f: F) => G | Promise<G>,
gh: (g: G) => H | Promise<H>,
hi: (h: H) => I | Promise<I>,
ij: (i: I) => J | Promise<J>,
jk: (j: J) => K | Promise<K>,
km: (k: K) => M | Promise<M>,
mn: (m: M) => N | Promise<N>,
): (a: A) => Promise<N>;
function pipeAsync() {
const fns = Array.prototype.slice.call(arguments, 0);
return function composed(initial) {
return fns.reduce((promise, fn) => {
return promise.then(fn);
}, Promise.resolve(initial));
};
};
/**
* Wraps array of promises with Promise.all
* @since 1.0.0
*/
const traversePromises = <A>(arrayOfPromises: Promise<A>[]): Promise<A[]> =>
Promise.all(arrayOfPromises);
/**
* @deprecated I have no idea how to type this function, any help appreciated
*/
function composeAsync() {
const fns = Array.prototype.slice.call(arguments, 0).reverse();
return function composed(initial) {
return fns.reduce((promise, fn) => {
return promise.then(fn);
}, Promise.resolve(initial));
};
};
/**
* @deprecated use traversePromises instead
*/
const mapAllAsync = curry(function mapAllAsync_<A>(transformer: ((a: A) => Promise<A>), collection: A[]) {
return Promise.all(map(transformer, collection));
});
export { pipeAsync, composeAsync, traversePromises, mapAllAsync }