Skip to content

Instantly share code, notes, and snippets.

@dijs
Last active February 21, 2017 17:55
Show Gist options
  • Save dijs/fd808856d8264a390466819985c528a9 to your computer and use it in GitHub Desktop.
Save dijs/fd808856d8264a390466819985c528a9 to your computer and use it in GitHub Desktop.
Conditional Chains
const when = c1 => {
return {
then: f => c1 && f(),
also: c2 => when(c1 && c2),
get and() {
return when(c1);
},
not(c3) {
return when(c1 && !c3);
}
};
}
const say = m => () => alert(m)
when(true).then(say(1));
when(true).and.also(true).then(say(2));
when(true).and.not(false).then(say(3));
when(true).and.also(true).and.also(true).then(say(4));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment