cannot invoke remote function inside match : Foreach loop

╄→гoц情女王★ 提交于 2019-12-05 03:44:11

There are a few issues here. The = operator is the match operator, it is not assignment. To explain the error, syntax-wise, this looks like function invocation on the left hand side of a match, which is not allowed.

But this is besides the point of your actual goal. If you want a set of user models that are updated with the new bcrypt information, you need to use a map function:

users = Enum.map(users, fn %User{id: id}=user ->
          %User{user| token: Comeonin.Bcrypt.hashpwsalt("#{id}")}
        end)

You have to remember that everything in Elixir is immutable.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!