Skip to content

Instantly share code, notes, and snippets.

@richdougherty
Last active January 4, 2016 04:38
Show Gist options
  • Save richdougherty/8569427 to your computer and use it in GitHub Desktop.
Save richdougherty/8569427 to your computer and use it in GitHub Desktop.
macro invert {
rule { { $x:ident <- $y:expr } } => {
$y(function($x) { return $x })
}
rule { { $x:ident <- $y:expr $rest ... } } => {
$y(function($x) {
return invert { $rest ... }
})
}
rule { { $y:expr } } => { $y }
}
invert {
y <- x.flatMap
z <- y.flatMap
z + 1
}
macro invert {
rule { { $ys ... | $x:ident -> $rest ... } } => {
($ys ...)(function($x) {
return invert { $rest ... }
})
}
rule { { $ys ... } } => {
$ys ...
}
}
invert {
x.onNext | next ->
next.flatMap | y ->
y+1
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment