9 ms·
I think you can in rust as long as args is a slice. Rust doesn't have varargs except for c interop. A slice or Vec of function pointers is the idiomatic way t
by monocasa 5y ago
I think you can in rust as long as args is a slice. Rust doesn't have varargs except for c interop. A slice or Vec of function pointers is the idiomatic way to do the same thing.
Something like:
fn compose<X, T>(start: Box<Fn(T) -> X>, args: Vec<Box<Fn(T) -> T>>) -> Fn(T) -> X {
move |x: X| {
let mut x = x;
for func in args.iter(). reversed() {
x = func(x);
}
start(x)
}
}
- slaymaker1907 5y agoThis only works if all of the functions return the same type. However, you can write a compose macro which operates as expected.