Skip to content

Instantly share code, notes, and snippets.

@bultas
Created August 30, 2016 13:30
Show Gist options
  • Save bultas/21c48ea84e5d1a1f7d3ba3a2b2c15948 to your computer and use it in GitHub Desktop.
Save bultas/21c48ea84e5d1a1f7d3ba3a2b2c15948 to your computer and use it in GitHub Desktop.
Dispatch - traverse functions as long as any function return something else then undefined
import {isNil} from 'ramda';
export function dispatch(...funcs) {
return function(...args) {
for (let fun of funcs) {
let ret = fun(...args);
if (!isNil(ret)) return ret;
}
return undefined;
};
}
// USAGE
dispatch(
dispatchAuthStarted,
dispatchAuthCompleted,
dispatchAuthFailed,
defaultAction
)('value');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment