File tree Expand file tree Collapse file tree 3 files changed +23
-45
lines changed
Expand file tree Collapse file tree 3 files changed +23
-45
lines changed Load Diff This file was deleted.
Original file line number Diff line number Diff line change 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
2539export default flow ;
Original file line number Diff line number Diff line change 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
2426export default flowRight ;
You can’t perform that action at this time.
0 commit comments