Wrapping Anon Fun

Are there other ways to wrap up functions in anonymous functions, e.g.

task = Task.async(fn -> do_some_work() end)

i.e. do we have options other than

fn -> ... end

I am doing this at the mo, prob not the best (but at least it’s not a macro)

def f(f), do:
    fn -> f end
1 Like

You can pass functions as arguments using this syntax:
&ModuleName.function/arity or &function/arity :slight_smile:

EDIT:
Applies also to function to variable assignment, i.e:
fun = &function/arity

1 Like

hmm should it work?

task = Task.async(&do_some_work/0)

2 Likes

You have to wrap it again (iirc).

This is closer to the problem I am having.

Late here, I am prob not thinking about this properly right now : ) Will think again in the morning.