The docs are definitely wrong. It should be Enumerable.reduce (or
Enumerable.List.reduce) instead of Enum.reduce. Enumerable.reduce is
expected to receive and return tagged tuples, opposite to Enum.reduce.
Could you please send a pull request or open up an issue with a link to
exactly where in the documentation it is wrong.

Thank you for reporting, it is very appreciated!



*José Valim*
www.plataformatec.com.br
Skype: jv.ptec
Founder and Director of R&D

On Sun, Sep 18, 2016 at 9:25 AM, Jordi Polo <mumi...@gmail.com> wrote:

>
> 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
> <https://groups.google.com/d/msgid/elixir-lang-core/5df8b5e1-5d9c-4edc-86e7-0c47e07c50a4%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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/CAGnRm4%2BspxzVeDi-bdaa5rGz1wQhHVLQ9%3Da27anpkFz7%2BP0VVw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to