Skip to content

Instantly share code, notes, and snippets.

@vsona

vsona/js

Last active Mar 26, 2018
Embed
What would you like to do?
js redux compose
const f1 = () => console.log('f', 1)
const f2 = () => console.log('f', 2)
const f3 = () => console.log('f', 3)
const f4 = () => console.log('f', 4)
const f5 = () => console.log('f', 5)
/**
* 合并单参数方法
*/
function compose(...funcs) {
if (funcs.length === 0) {
return arg => arg
}
if (funcs.length === 1) {
return funcs[0]
}
return funcs.reduce((a, b) => (...args) => a(b(...args)))
}
let c = compose(f1, f2, f3, f4, f5)
c()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.