Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/elixir/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Elixir编译错误:具有多个子句和默认值的定义需要标头_Elixir - Fatal编程技术网

Elixir编译错误:具有多个子句和默认值的定义需要标头

Elixir编译错误:具有多个子句和默认值的定义需要标头,elixir,Elixir,我发现Elixir编译错误:具有多个子句和默认值的定义需要一个标题。用于以下函数。我不清楚为什么我会犯这个错误?对如何解决这个问题有什么建议吗 def stream(query, opts \\ []) do initial_key = Keyword.get(opts, :initial_key, 0) key_name = Keyword.get(opts, :key_name, :id) chunk_size = Keyword.get(opts, :chunk

我发现Elixir编译错误:具有多个子句和默认值的定义需要一个标题。用于以下函数。我不清楚为什么我会犯这个错误?对如何解决这个问题有什么建议吗

  def stream(query, opts \\ []) do
    initial_key = Keyword.get(opts, :initial_key, 0)
    key_name = Keyword.get(opts, :key_name, :id)
    chunk_size = Keyword.get(opts, :chunk_size, 500)

    Stream.resource(fn -> {query, initial_key} end,
      fn {query, last_seen_key} ->
        results = query
          |> Ecto.Query.where([r], field(r, ^key_name) > ^last_seen_key)
          |> Ecto.Query.limit(^chunk_size) 
          |> __ENV__.module.all

        case List.last(results) do
          %{^key_name => last_key} ->
            {results, {query, last_key}}
          nil ->
            {:halt, {query, last_seen_key}}
        end
      end,
      fn _ -> [] end)
  end
错误消息:

== Compilation error on file lib/peanutbutter/repo.ex ==
** (CompileError) lib/peanutbutter/repo.ex:3: definitions with multiple clauses and default values require a header. Instead of:

    def foo(:first_clause, b \\ :default) do ... end
    def foo(:second_clause, b) do ... end

one should write:

    def foo(a, b \\ :default)
    def foo(:first_clause, b) do ... end
    def foo(:second_clause, b) do ... end

def stream/2 has multiple clauses and defines defaults in one or more clauses
    lib/peanutbutter/repo.ex:3: (module)
    (stdlib) erl_eval.erl:670: :erl_eval.do_apply/6
    (elixir) lib/kernel/parallel_compiler.ex:117: anonymous fn/4 in Kernel.ParallelCompiler.spawn_compilers/1

当您使用exto.Repo、otp_app::my_app时,exto已经定义了一个名为stream/2的函数。您将需要调用其他函数。

您是否有流函数的另一个定义在该函数的上方或下方?我找不到另一个流函数的定义哪个流线会引发此错误?您可以发布包含stacktrace的完整错误消息吗?repo.ex中的第3行只是加载文件,其中包含itEcto中的stream函数。当您使用exto.repo、otp_app::my_app时,该函数已经定义了一个名为stream/2的函数。