Skip to content

Instantly share code, notes, and snippets.

@simonpai
Created March 15, 2019 13:20
Show Gist options
  • Save simonpai/cd7e6f21804e8fc7e7cd70910eecbc20 to your computer and use it in GitHub Desktop.
Save simonpai/cd7e6f21804e8fc7e7cd70910eecbc20 to your computer and use it in GitHub Desktop.
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