simo
simo

Reputation: 24590

How to pass a function to Enum.each?

I need to pass the items of list to a function, using Enum.each

ex:
users= [1, 2, 3, 4, 5]

#how to link the handler_user function in Enum.each?
users 
|> Enum.each handler_user

def handler_user user_id
end

So, how would I do the link?

Upvotes: 1

Views: 1377

Answers (1)

Gazler
Gazler

Reputation: 84180

You must use &/1 to capture the function:

users = [1, 2, 3, 4, 5]

Enum.each(users, &handler_user/1)

def handler_user(user_id) do
...
end

Upvotes: 9

Related Questions