Skip to content

Instantly share code, notes, and snippets.

@garretttaco
Created May 9, 2019 17:34
Show Gist options
  • Save garretttaco/a3aac467b8e8836dc052f1c7f6bf971b to your computer and use it in GitHub Desktop.
Save garretttaco/a3aac467b8e8836dc052f1c7f6bf971b to your computer and use it in GitHub Desktop.
Use MapSets to find differences in new ids vs current/existing ids. This really could be used for any many to many ids table.
def diff_ids_update(new, existing) do
# Use MapSets to find differences in new ids vs current/existing ids. This really could be used for any many to many ids table.
new = new |> MapSet.new()
existing = existing |> MapSet.new()
remove = MapSet.difference(existing, new) |> MapSet.to_list()
add = MapSet.difference(new, existing) |> MapSet.to_list()
{remove, add}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment