我需要使用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
那么,我该如何进行链接?
答案 0 :(得分:8)
您必须使用&/1来捕获该功能:
users = [1, 2, 3, 4, 5]
Enum.each(users, &handler_user/1)
def handler_user(user_id) do
...
end