Skip to content
This repository was archived by the owner on Jan 26, 2022. It is now read-only.

Commit 37fe9d4

Browse files
authored
Change examples to use destructuring
Fixes #11.
1 parent d5bd93c commit 37fe9d4

File tree

1 file changed

+25
-15
lines changed

1 file changed

+25
-15
lines changed

README.md

+25-15
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,15 @@ The `Function.flow` static method creates a new function from several sub-functi
1616
```js
1717
Function.flow(...fns);
1818

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);
2022
f(5, 7); // Evalutes to ((5 + 7) * 2) + 1.
2123

22-
const g = Function.flow(x => x + 1);
24+
const g = flow(x => x + 1);
2325
g(5); // Evaluates to 6.
2426

25-
const h = Function.flow();
27+
const h = flow();
2628
h(5); // Evalutes to 5.
2729
```
2830

@@ -50,10 +52,12 @@ The new function will always return that value, no matter what arguments it is g
5052
```js
5153
Function.constant(value);
5254

53-
const f = Function.constant(5);
55+
const { constant } = Function;
56+
57+
const f = constant(5);
5458
f(11, 0, 3); // Evaluates to 5.
5559

56-
const g = Function.constant();
60+
const g = constant();
5761
g(11, 0, 3); // Evaluates to undefined.
5862
```
5963

@@ -70,8 +74,10 @@ The `Function.identity` static method always returns its first argument.
7074
```js
7175
Function.identity(value);
7276

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.
7581
```
7682

7783
| Precedent | Example
@@ -88,20 +94,22 @@ of sub-functions to a given input value, returning the final sub-function’s re
8894
```js
8995
Function.pipe(input, ...fns);
9096

97+
const { pipe } = Function;
98+
9199
// Evalutes to (5 + 7) * 2.
92-
Function.pipe(5,
100+
pipe(5,
93101
x => x + 1,
94102
x => x * 2,
95103
);
96104

97105
// Evaluates to 5.
98-
Function.pipe(5);
106+
pipe(5);
99107

100108
// Evaluates to undefined.
101-
Function.pipe();
109+
pipe();
102110

103111
// Throws a SyntaxError.
104-
await Function.pipeAsync('x', JSON.parse);
112+
pipe('x', JSON.parse);
105113
```
106114

107115
The first sub-function is applied to `input`,
@@ -149,22 +157,24 @@ The promise will resolve to the final sub-function’s result.
149157
```js
150158
Function.pipeAsync(input, ...fns);
151159

160+
const { pipeAsync } = Function;
161+
152162
// A promise that will resolve to ((await (await fetch(await url, options)).json()) + 1) * 2.
153-
Function.pipeAsync(url,
163+
pipeAsync(url,
154164
x => fetch(x, options),
155165
x => x.json(),
156166
x => x + 1,
157167
x => x * 2,
158168
);
159169

160170
// A promise that will resolve to 5.
161-
Function.pipeAsync(5);
171+
pipeAsync(5);
162172

163173
// A promise that will resolve to undefined.
164-
Function.pipeAsync();
174+
pipeAsync();
165175

166176
// A promise that will reject with a SyntaxError.
167-
Function.pipeAsync('x', JSON.parse);
177+
pipeAsync('x', JSON.parse);
168178
```
169179

170180
The input is first `await`ed.

0 commit comments

Comments
 (0)