Add DedupeStrings to remove repeated values from a string slice #1
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Removing repeated values from a slice of strings while keeping the original order is something nearly every program ends up writing by hand, and the standard library has nothing for it before generics and sorting-based helpers arrive. A small function here would save that copy-and-paste in every project.
Definition of done:
DedupeStrings(input []string) []stringreturns a new slice containing each value once, in the order each value first appeared, with a doc comment and table-driven tests covering an empty slice, a nil slice, a slice with no repeats, a slice that is all the same value, and repeats that are not next to each other.Model: opus-5