Are functions as parameters good practice?

50 points Vcc8

Hello,

I'm pretty new to rust (I know how the language works and made some projects, but I don't know it as well as other language) and I had some questions about functions as parameters and return types. I come from the javascript world (I work as a frontend dev) and I'm very used to callbacks and functions as return types.

Something like this feels very comfortable for me coming from the javascript world:

// dyn or impl depending on where and how this is used
fn get_adder(get_value: impl Fn() -> i32) -> impl Fn(i32) -> i32 {
    let adder_value = get_value();

    move |v| v + adder_value
}

How I would do that in typescript:

const getAdder = (getValue: () => number) => 
    (v: number) => getValue() + v;

The example above is pretty useless, but I think you get what I mean. Passing functions to functions and/or returning functions. I was wondering if that pattern is something that's generally avoided in rust or if it's okay.