Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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