Created
October 30, 2015 08:33
-
-
Save XeCycle/621d8c8c48d1729daceb to your computer and use it in GitHub Desktop.
An emulation of do notation that remains valid javascript
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
macro DO { | |
rule { ($name:ident <- $expr:expr, ret($any...)) } => { ($expr).map($name => ($any...)) } | |
rule { ($name:ident <- $expr:expr, $any...) } => { ($expr).chain($name => DO($any...))} | |
rule { ($expr:expr, ret($any...)) } => { ($expr).map(() => ($any...)) } | |
rule { ($expr:expr, $any...) } => { ($expr).chain(() => DO($any...)) } | |
rule { ($expr:expr) } => { ($expr) } | |
} | |
export DO; |
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
function render$656() { | |
return fetchA().chain(resA$660 => fetchB().chain(resB$661 => fetchC().map(resC$662 => Element({ | |
A: resA$660, | |
B: resB$661, | |
C: resC$662 | |
})))); | |
} |
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
function render() { | |
return DO( | |
resA <- fetchA(), | |
resB <- fetchB(), | |
resC <- fetchC(), | |
ret(Element({ | |
A: resA, | |
B: resB, | |
C: resC | |
})) | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment