I am squinting at how Elixir handles function callbacks… specifically, I’m wondering whether you can capture a function WITH arguments attached.
So instead of something like this:
myfunc = fn(a,b) -> a + b end myfunc2 = &(IO.puts/1) myfunc.(1,2) myfunc2.("Hello World!")
where you have to provide the arguments when you call the captured functions, I’m wondering if there is some way to capture the ARGUMENTs too so that you can just say “that thing I saved? Run that now please.”
I can’t even think whether such a structure would be possible in any language. I’m thinking of something more like PHP’s
call_user_func(). I suppose the proper way to do something like this in Elixir would be to implement a behavior with a defined arity and dispatch to it. The thing that sent my brain into a spin was thinking that the callback may not have the proper variable available when it needed to execute. Sorry if I’m talking crazy…