mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-03 16:47:49 +00:00
Move internal modules to “internal” folder.
This commit is contained in:
38
.internal/createFlow.js
Normal file
38
.internal/createFlow.js
Normal file
@@ -0,0 +1,38 @@
|
||||
/**
|
||||
* Creates a `flow` or `flowRight` function.
|
||||
*
|
||||
* @private
|
||||
* @param {boolean} [fromRight] Specify iterating from right to left.
|
||||
* @returns {Function} Returns the new flow function.
|
||||
*/
|
||||
function createFlow(fromRight) {
|
||||
return (...funcs) => {
|
||||
const length = funcs.length;
|
||||
|
||||
let func;
|
||||
let wrapper;
|
||||
let index = length;
|
||||
|
||||
if (fromRight) {
|
||||
funcs.reverse();
|
||||
}
|
||||
while (index--) {
|
||||
func = funcs[index];
|
||||
if (typeof func != 'function') {
|
||||
throw new TypeError('Expected a function');
|
||||
}
|
||||
}
|
||||
return function(...args) {
|
||||
const value = args[0];
|
||||
let index = 0;
|
||||
let result = length ? funcs[index].apply(this, args) : value;
|
||||
|
||||
while (++index < length) {
|
||||
result = funcs[index].call(this, result);
|
||||
}
|
||||
return result;
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
export default createFlow;
|
||||
Reference in New Issue
Block a user