COLLECTED BY
Organization:
Internet Archive
Focused crawls are collections of frequently-updated webcrawl data from narrow (as opposed to broad or wide) web crawls, often focused on a single domain or subdomain.
The Wayback Machine - https://web.archive.org/web/20201220220947/https://github.com/lodash/lodash/blob/master/flow.js
Permalink
Cannot retrieve contributors at this time
41 lines (40 sloc)
1005 Bytes
/**
* Composes a function that returns the result of invoking the given functions
* with the `this` binding of the created function, where each successive
* invocation is supplied the return value of the previous.
*
* @since 3.0.0
* @category Util
* @param {Function[] } [funcs] The functions to invoke.
* @returns {Function } Returns the new composite function.
* @see flowRight
* @example
*
* import add from 'lodash/add'
*
* function square(n) {
* return n * n
* }
*
* const addSquare = flow(add, square)
* addSquare(1, 2)
* // => 9
*/
function flow ( ...funcs ) {
const length = funcs . length
let index = length
while ( index -- ) {
if ( typeof funcs [ index ] !== 'function' ) {
throw new TypeError ( 'Expected a function' )
}
}
return function ( ...args ) {
let index = 0
let result = length ? funcs [ index ] . apply ( this , args ) : args [ 0 ]
while ( ++ index < length ) {
result = funcs [ index ] . call ( this , result )
}
return result
}
}
export default flow
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session.
You signed out in another tab or window. Reload to refresh your session.