Enum.map_reduce (mis) understanding?

258 views
Skip to first unread message

Alex Shneyderman

unread,
Nov 10, 2014, 1:35:58 PM11/10/14
to elixir-l...@googlegroups.com
Hi, all!

What am I doing wrong? 

iex(19)> [:html, :txt] |> Enum.map_reduce Map.new,
...(19)>    fn(r, acc) -> acc |> Dict.put r, r end
** (MatchError) no match of right hand side value: %{html: :html}
    (elixir) lib/enum.ex:1036: Enum."-map_reduce/3-lists^mapfoldl/2-0-"/3

Cheers,
Alex.

Alex Shneyderman

unread,
Nov 10, 2014, 1:46:58 PM11/10/14
to elixir-l...@googlegroups.com
never mind. a case rtfm, sorry.

Alex Shneyderman

unread,
Nov 10, 2014, 2:43:35 PM11/10/14
to elixir-l...@googlegroups.com
actually reading the spec it seems to be a bit inaccurate (hence my confusion). Should not this
  • map_reduce(t, any, (element, any -> any)) :: any
be something like this:
  • map_reduce(t, any, (element, any -> {any,any})) :: {any, any}
?

I realize that {any,any} is still any but the function is very specific about returning a tuple, so it might be a little more clear to have that in the spec. Unless I am missing something obvious about the specs.

José Valim

unread,
Nov 10, 2014, 6:09:33 PM11/10/14
to elixir-l...@googlegroups.com
Yes, you are right. :) an issue or pull request is appreciated :)
--
You received this message because you are subscribed to the Google Groups "elixir-lang-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-ta...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--


José Valim
Skype: jv.ptec
Founder and Lead Developer

Reply all
Reply to author
Forward
0 new messages