I want to be able to create a higher-order function (called g
) that takes in a function (called f
). g
should pass in the first parameter to f
and return a new function.
The use case is that I want to initiate a database connection in g
and pass it functions that accept a database connection.
fn f1(a: i32, b: String) -> String {
b
}
fn f2(a: i32, c: i64, d: i16) -> i32 {
1000
}
fn g<T>(f: fn(a: i32, arbitrary_arguments_type) -> T) -> fn(arbitrary_arguments_type) -> T {
move |arbitrary_arguments| f(1, arbitrary_arguments)
}
fn main() {
g(f1)("hello".to_string());
g(f2)(10, 11);
}
How do I create a macro that takes in as an argument a function with a more than 1 parameter, where first parameter is of a certain type, and supplies that argument for that first function?