@@ -16,13 +16,15 @@ The `Function.flow` static method creates a new function from several sub-functi
16
16
``` js
17
17
Function .flow (... fns);
18
18
19
- const f = Function .flow ((x , y ) => x + y, x => x * 2 , x => x + 1 );
19
+ const { flow } = Function ;
20
+
21
+ const f = flow ((x , y ) => x + y, x => x * 2 , x => x + 1 );
20
22
f (5 , 7 ); // Evalutes to ((5 + 7) * 2) + 1.
21
23
22
- const g = Function . flow (x => x + 1 );
24
+ const g = flow (x => x + 1 );
23
25
g (5 ); // Evaluates to 6.
24
26
25
- const h = Function . flow ();
27
+ const h = flow ();
26
28
h (5 ); // Evalutes to 5.
27
29
```
28
30
@@ -50,10 +52,12 @@ The new function will always return that value, no matter what arguments it is g
50
52
``` js
51
53
Function .constant (value);
52
54
53
- const f = Function .constant (5 );
55
+ const { constant } = Function ;
56
+
57
+ const f = constant (5 );
54
58
f (11 , 0 , 3 ); // Evaluates to 5.
55
59
56
- const g = Function . constant ();
60
+ const g = constant ();
57
61
g (11 , 0 , 3 ); // Evaluates to undefined.
58
62
```
59
63
@@ -70,8 +74,10 @@ The `Function.identity` static method always returns its first argument.
70
74
``` js
71
75
Function .identity (value);
72
76
73
- Function .identity (5 ); // Evaluates to 5.
74
- Function .identity (); // Evaluates to undefined.
77
+ const { identity } = Function ;
78
+
79
+ identity (5 ); // Evaluates to 5.
80
+ identity (); // Evaluates to undefined.
75
81
```
76
82
77
83
| Precedent | Example
@@ -88,20 +94,22 @@ of sub-functions to a given input value, returning the final sub-function’s re
88
94
``` js
89
95
Function .pipe (input, ... fns);
90
96
97
+ const { pipe } = Function ;
98
+
91
99
// Evalutes to (5 + 7) * 2.
92
- Function . pipe (5 ,
100
+ pipe (5 ,
93
101
x => x + 1 ,
94
102
x => x * 2 ,
95
103
);
96
104
97
105
// Evaluates to 5.
98
- Function . pipe (5 );
106
+ pipe (5 );
99
107
100
108
// Evaluates to undefined.
101
- Function . pipe ();
109
+ pipe ();
102
110
103
111
// Throws a SyntaxError.
104
- await Function . pipeAsync (' x' , JSON .parse );
112
+ pipe (' x' , JSON .parse );
105
113
```
106
114
107
115
The first sub-function is applied to ` input ` ,
@@ -149,22 +157,24 @@ The promise will resolve to the final sub-function’s result.
149
157
``` js
150
158
Function .pipeAsync (input, ... fns);
151
159
160
+ const { pipeAsync } = Function ;
161
+
152
162
// A promise that will resolve to ((await (await fetch(await url, options)).json()) + 1) * 2.
153
- Function . pipeAsync (url,
163
+ pipeAsync (url,
154
164
x => fetch (x, options),
155
165
x => x .json (),
156
166
x => x + 1 ,
157
167
x => x * 2 ,
158
168
);
159
169
160
170
// A promise that will resolve to 5.
161
- Function . pipeAsync (5 );
171
+ pipeAsync (5 );
162
172
163
173
// A promise that will resolve to undefined.
164
- Function . pipeAsync ();
174
+ pipeAsync ();
165
175
166
176
// A promise that will reject with a SyntaxError.
167
- Function . pipeAsync (' x' , JSON .parse );
177
+ pipeAsync (' x' , JSON .parse );
168
178
```
169
179
170
180
The input is first ` await ` ed.
0 commit comments