Enum.uniq_by/3 with 3rd arg - a function that decides which value to keep

28 views
Skip to first unread message

Anastasiya Dyachenko

unread,
Mar 19, 2021, 3:29:49 PM3/19/21
to elixir-lang-core
Hi! I'd like to propose adding a 3rd optional argument to Enum.uniq_by function, which will decide which one of the duplicated values should be kept. This function will accept 2 values and return one of them, that should be kept.

Example: 

Enum.uniq_by(
  [a: 1, a: 2], 
  fn {k, v} -> k end, 
  fn {_, v_a} = a,  {_, v_b} = b ->
    if v_a >= v_b, do: a, else: b
  end
)
=> [a: 2]

José Valim

unread,
Mar 20, 2021, 3:13:57 AM3/20/21
to elixir-l...@googlegroups.com
Hi Anastasiya, I like the proposal. A PR will be appreciated, thank you!

--
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-co...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/b0e4b7f1-0a8f-406c-89d2-84b51edb500bn%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages