This Gist was automatically created by Carbide, a free online programming environment.
Last active
February 21, 2017 17:55
-
-
Save dijs/fd808856d8264a390466819985c528a9 to your computer and use it in GitHub Desktop.
Conditional Chains
This file contains hidden or 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
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