我正在编写Elixir编程书,其中一个例子我得到了一个编译错误,我错过了end
,所以我添加了end
并且它有效..
事情是,我无法弄清楚它正在关闭什么!
但它有效!???
这是一个奇怪的灵丹妙药吗?怎么回事?
defmodule Rumbl.Repo do
@moduledoc """
In memory repository
"""
def all(Rumbl.User) do
[%Rumbl.User{id: "1", name: "Jose", username: "josevalim", password: "elixir"},
%Rumbl.User{id: "2", name: "Alison", username: "allygrrl", password: "elixir123"},
%Rumbl.User{id: "3", name: "Susan", username: "susanQ",password: "elixir321"}]
end
def all(_module), do: []
def get(module, id) do
Enum.find all(module), fn map -> map.id == id end
end
def get_by(module, params) do
Enum.find all(module), fn map ->
Enum.all?(params, fn {key, val} -> Map.get(map, key) == val end)
end
end
end
答案 0 :(得分:4)
您尚未在fn map -> ...
中关闭get_by/2
所以看起来应该是这样的:
def get_by(module, params) do
Enum.find all(module), fn map ->
Enum.all?(params, fn {key, val} -> Map.get(map, key) == val end)
end # <- end needed here
end