如何将函数传递给Enum.each?

时间:2016-05-31 10:34:17

标签: elixir

我需要使用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

那么,我该如何进行链接?

1 个答案:

答案 0 :(得分:8)

您必须使用&/1来捕获该功能:

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

Enum.each(users, &handler_user/1)

def handler_user(user_id) do
...
end