Created
March 15, 2019 13:20
-
-
Save simonpai/cd7e6f21804e8fc7e7cd70910eecbc20 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export function compose(...fns) { | |
const [fn0, ...rest] = fns.reverse(); | |
return (...args) => rest.reduce((acc, fn) => fn(acc), fn0(...args)); | |
} | |
export function mapValue(obj, fn) { | |
return Object.keys(obj).reduce((acc, key) => { | |
acc[key] = fn(obj[key]); | |
return acc; | |
}, {}); | |
} | |
export function disperse(obj, fn) { | |
return typeof obj !== 'object' ? fn(obj) : mapValue(obj, v => disperse(v, fn)); | |
} | |
// | |
state = { | |
...S.init(640, 480)(), | |
actions: disperse(S, a => compose(this.setState, a)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment