I'm writing to the core list because it seems to me a problem with the 
language.

To teach myself, I've done this silly thing, mostly following the official 
documentation:

defmodule NewTable do
  defstruct data: []
  @type t :: %__MODULE__{
    data: nonempty_list(any)
  }
end

defimpl Enumerable, for: NewTable do
  def reduce(t, acc, fun) do
    Enum.reduce(t.data, acc, fun)
  end
  def count(t) do
    {:ok, length(t.data)}
  end
  def member?(t, x) do
    {:ok, Enum.member?(t.data, x)}
  end
end



I know there is no point of implementing Enumerable for a list but this is 
just a learning exercise.
count and member work. 
The above reduce method does not work. Trying to use Enum.at, Enum.max, etc 
on that struct will give back several errors about anonymous functions 
which are not clear at all.
I've tried with current master also, I get a different set of errors and 
even something I really do not know how to interpret:

Enum.max(%NewTable{ data: [1,2]})
{:cont, {:cont, #Reference<0.0.4.735>}}

I've tried to use  :lists.foldl(fun, acc, t.data) instead of 
Enum.reduce(t.data, acc, fun) but gets the same kind of error.

I'm thinking this may be a language issue because if the above code is 
totally broken, it seems to me, reading the docs that it should work, so 
maybe the docs are misleading? Or maybe I'm just too new and I'm using some 
old way of thinking?
And in any case the errors provided does not give a hint about the problem


-- 
You received this message because you are subscribed to the Google Groups 
"elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elixir-lang-core+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/elixir-lang-core/5df8b5e1-5d9c-4edc-86e7-0c47e07c50a4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to