eraseDupsKeepRight #
In this file, we define the eraseDupsKeepRight convenience function that removes duplicates from a given list while keeping the rightmost occurrence.
This function assumes DecidableEq on the list elements.
As one would expect, the resulting list is free of duplicates and still contains the same members as the original list, which
is shown in theorems below.
If two lists have no duplicates and have the same elements, then their length is the same. Note that the lists are not necessarily equal since the order of elements may differ.
Remove duplicates from a list, keeping the rightmost occurrense.
Equations
- [].eraseDupsKeepRight = []
- (hd :: tl).eraseDupsKeepRight = if hd ∈ tl then tl.eraseDupsKeepRight else hd :: tl.eraseDupsKeepRight
Instances For
The deduplicated list contains the same elements as the original list.
The deduplicated list indeed has no duplicates.
Calling eraseDupsKeepRight a second time does not change anything anymore.
If two lists contain the same elements, then calling eraseDupsKeepRight on both ends up with lists of equal length. Again the lists might not be equal as they could differ in their order of elements.