Hey guys, this is my first proposal so please be kind :) I don't know if WE 
need this functionality, but I certainly needed this so I already developed 
it. Obviously I'm not that familiar with Elixir yet so it might happen that 
there is something very simmilar somewhere in the code, but I looked and 
couldn't find it.


My idea is to "cleanup" lists which have duplicate values, but in a way 
that will merge the duplicate values (not just ignore them like uniq/1 does) 
by using given function (one of the params). Please let me know what you 
think.


Examples:


      iex> Enum.merge([1, 2, 3, 3, 2, 1], fn (x, y) -> x + y end)

      [2, 4, 6]


      # This one is simmilar to `Enum.uniq/1`

      iex> Enum.merge([1, 2, 3, 3, 2, 1], fn (x, _y) -> x end)

      [1, 2, 3]


      iex> Enum.merge_by([{1, :x}, {2, :y}, {1, :z}], fn (x, _) -> x end, 
fn {x, _} -> x end)

      [{1, :x}, {2, :y}]


      iex> Enum.merge_by([a: {:tea, 2}, b: {:tea, 2}, c: {:coffee, 1}], fn 
(x, _) -> x end, fn {_, y} -> y end)

      [a: {:tea, 2}, c: {:coffee, 1}]


      iex> Enum.merge_by([%{k: "a", v: 1}, %{k: "b", v: 2}, %{k: "a", v: 
3}, %{k: "b", v: 4}], fn(t1, t2) -> %{t1 | v: t1.v + t2.v} end, fn s -> s.k 
end)

      [%{k: "a", v: 4}, %{k: "b", v: 6}]


Because I'm new here I already created PR on github which obviously got 
closed immediately... :) But there is an upside to this, I already 
implemented this functionality so you can see the examples in more 
"human-readable" form on github 
(https://github.com/elixir-lang/elixir/pull/4854/files) to better 
understand what I wanted to achieve :) 


Please let me know if you think this would be useful and maybe if there is 
no simmilar functionality already!

-- 
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/d0e39a77-a693-4436-8c44-57e111d06602%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to