Skip to content

Commit 454219f

Browse files
committed
Simplify flow modules.
1 parent 379b7a0 commit 454219f

File tree

3 files changed

+23
-45
lines changed

3 files changed

+23
-45
lines changed

.internal/createFlow.js

Lines changed: 0 additions & 38 deletions
This file was deleted.

flow.js

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1-
import createFlow from './.internal/createFlow.js';
2-
31
/**
42
* Creates a function that returns the result of invoking the given functions
53
* with the `this` binding of the created function, where each successive
64
* invocation is supplied the return value of the previous.
75
*
86
* @since 3.0.0
97
* @category Util
10-
* @param {...(Function|Function[])} [funcs] The functions to invoke.
8+
* @param {Function[]} [funcs] The functions to invoke.
119
* @returns {Function} Returns the new composite function.
1210
* @see flowRight
1311
* @example
@@ -20,6 +18,22 @@ import createFlow from './.internal/createFlow.js';
2018
* addSquare(1, 2);
2119
* // => 9
2220
*/
23-
const flow = createFlow();
21+
function flow(funcs) {
22+
const length = funcs ? funcs.length : 0;
23+
let index = length;
24+
while (index--) {
25+
if (typeof funcs[index] != 'function') {
26+
throw new TypeError('Expected a function');
27+
}
28+
}
29+
return function(...args) {
30+
let index = 0;
31+
let result = length ? funcs[index].apply(this, args) : args[0];
32+
while (++index < length) {
33+
result = funcs[index].call(this, result);
34+
}
35+
return result;
36+
};
37+
}
2438

2539
export default flow;

flowRight.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import createFlow from './.internal/createFlow.js';
1+
import flow from './flow.js';
22

33
/**
44
* This method is like `flow` except that it creates a function that
55
* invokes the given functions from right to left.
66
*
77
* @since 3.0.0
88
* @category Util
9-
* @param {...(Function|Function[])} [funcs] The functions to invoke.
9+
* @param {Function[]} [funcs] The functions to invoke.
1010
* @returns {Function} Returns the new composite function.
1111
* @see flow
1212
* @example
@@ -19,6 +19,8 @@ import createFlow from './.internal/createFlow.js';
1919
* addSquare(1, 2);
2020
* // => 9
2121
*/
22-
const flowRight = createFlow(true);
22+
function flowRight(funcs) {
23+
return flow(funcs.reverse());
24+
}
2325

2426
export default flowRight;

0 commit comments

Comments
 (0)