I'm working on a Concurrent FRP library based on Elm, and I'd like to be able to accept variadic arguments to methods on a struct. For instance, I have a lift2
function which applies a function to two sources of data (a "signal" in the Elm jargon) and returns a new source of data
signal.lift2(other_signal, |i, j| -> usize { i + j})
I'd like to be able to define something like this:
signal.liftn(other_signal1, other_signal2, |i, j, k| -> usize { i + j + k })
The 'ugly' solution is to nest:
signal.lift2(
other_signal1.lift2(
other_signal2,
|i, j| -> (usize, usize) { (i, j) },
),
|i, (j, k)| -> usize { i + j + k }
)
I'd really like to be able to keep method-chaining syntax, so I can write execution chains like:
signal
.lift2(other, |i, j| -> usize { i + j})
.fold(0, |i, j| -> usize { i + j } )
.lift(|i| -> bool { i > 0 })
Is there a way to define macros that operate like methods? Ideally
signal.liftn!(a, b, ...n, |i, j, ...n| {})
Thanks for any help!