-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathall.d.ts
100 lines (100 loc) · 2.83 KB
/
all.d.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
export = all;
/**
* @name all
*
* @synopsis
* ```coffeescript [specscript]
* all(...args, funcsArray Array<function>) -> result Promise|Array
*
* all(funcsArray Array<function>)(...args) -> result Promise|Array
*
* all(...args, funcsObject Object<function>) -> result Promise|Object
*
* all(funcsObject Object<function>)(...args) -> result Promise|Object
* ```
*
* @description
* Function executor and composer. Accepts either an array of functions or an object of functions as the values. Calls each function of the provided array or object in parallel with the provided arguments. Returns either an array or object of the results of the function executions.
*
* ```javascript [playground]
* const createArrayOfGreetingsFor = all([
* name => `Hi ${name}`,
* name => `Hey ${name}`,
* name => `Hello ${name}`,
* ])
*
* const arrayOfGreetingsForFred = createArrayOfGreetingsFor('Fred')
*
* console.log(arrayOfGreetingsForFred)
* // ['Hi Fred', 'Hey Fred', 'Hello Fred']
*
* const createObjectOfGreetingsFor = all({
* hi: name => `Hi ${name}`,
* hey: name => `Hey ${name}`,
* hello: name => `Hello ${name}`,
* })
*
* const objectOfGreetingsForJane = createObjectOfGreetingsFor('Jane')
*
* console.log(objectOfGreetingsForJane)
* // { hi: 'Hi Jane', hey: 'Hey Jane', hello: 'Hello Jane' }
* ```
*
* `all` can simultaneously compose objects and handle promises.
*
* ```javascript [playground]
* const identity = value => value
*
* const userbase = new Map()
* userbase.set('1', { _id: 1, name: 'George' })
*
* const getUserByID = async id => userbase.get(id)
*
* const getAndLogUserById = pipe([
* all({
* id: identity,
* user: getUserByID,
* }),
* tap(({ id, user }) => {
* console.log(`Got user ${JSON.stringify(user)} by id ${id}`)
* }),
* ])
*
* getAndLogUserById('1') // Got user {"_id":1,"name":"George"} by id 1
* ```
*
* @execution concurrent
*/
declare function all(...args: any[]): any;
declare namespace all {
/**
* @name all.series
*
* @synopsis
* ```coffeescript [specscript]
* all.series(...args, funcsArray Array<function>) -> result Promise|Array
*
* all.series(funcsArray Array<function>)(...args) -> result Promise|Array
* ```
*
* @description
* `all` with serial execution.
*
* ```javascript [playground]
* const sleep = ms => () => new Promise(resolve => setTimeout(resolve, ms))
*
* all.series([
* greeting => console.log(greeting + ' world'),
* sleep(1000),
* greeting => console.log(greeting + ' mom'),
* sleep(1000),
* greeting => console.log(greeting + ' goodbye'),
* ])('hello') // hello world
* // hello mom
* // hello goodbye
* ```
*
* @execution series
*/
function series(...args: any[]): any;
}