I am having two lists, an old one and a new one
old = [{:a, :c, 1}, {:b, :d, 2}, {:c, :a, 1}]
new = [{:a, :c, 2}, {:b, :d, 3}, {:c, :b, 1}]
I want to compare the atoms of the older one with the newer one, if the older tuple exists in a new one then only take the tuple from the new list else take both in the final output.
the final output will look something like this
final = [{:a, :c, 2}, {:b, :d, 3}, {:c, :a, 1}, {:c, :b, 1}]
i have tried it using this code but I am not able to get the correct result
Enum.map(old, fn x ->
Enum.map(new, fn y ->
if Tuple.delete_at(x, tuple_size(x) - 1) == Tuple.delete_at(y, tuple_size(y) - 1) do
List.delete(old, x)
end
end)
end)
Note: {:a, :b, 1} and {:a, :b, 2} are same as we are comparing them on atoms only.
Thanks






















