Efficient deduplicating consecutive elements in a list

I receive a list, which may contain (multiple times) two or more identical elements consecutively. Something like

["a", "b", "c", "b", "b", "c", "b", "d", "d"]

After processing there should be no identical elements one after another anymore:

["a", "b", "c", "b", "c", "b", "d"]

What would be Elixir experts’ suggestion on how to process such lists a) efficiently and b) preferably in an Elixir-idiomatic way?

1 Like

Enum.dedup, or Enum.dedup_by…



Gosh! Absolutely. When looking at the functions I somehow thought this one was deduplicating “globally”. Thanks!

This would be Enum.uniq :slight_smile:

:slight_smile: Yes, I know, I know… mercy please :wink: