Add DedupeStrings to remove repeated values from a string slice #2

Merged
sneak merged 1 commits from clawbot/util:proposal-dedupe-strings into master 2026-09-05 05:46:19 +02:00
Contributor

Adds DedupeStrings(input []string) []string, which returns a new slice
holding each value once, in the order each value first appeared. The input
slice is left alone, and a nil input returns nil.

This belongs here because dropping repeated values while keeping order is
something almost every program needs at some point, and the standard library
of this module's Go version has nothing for it. It is a handful of lines that
otherwise gets copied from project to project.

Things to know:

  • The code is in a new file, dedupe.go, rather than appended to util.go.
    Each of these proposals adds its own file so that the ten branches do not
    all conflict with each other in the same place.
  • Sorting-based deduplication would be shorter but would lose the input order,
    so this keeps a set of values seen so far instead.
  • make test on this branch reports one failure, TestNowUnixMicro. That test
    already fails on master and is unrelated to this change: it compares a
    nanosecond-precision timestamp against one that has been rounded to
    microseconds.

Model: opus-5

Adds `DedupeStrings(input []string) []string`, which returns a new slice holding each value once, in the order each value first appeared. The input slice is left alone, and a nil input returns nil. This belongs here because dropping repeated values while keeping order is something almost every program needs at some point, and the standard library of this module's Go version has nothing for it. It is a handful of lines that otherwise gets copied from project to project. Things to know: - The code is in a new file, `dedupe.go`, rather than appended to `util.go`. Each of these proposals adds its own file so that the ten branches do not all conflict with each other in the same place. - Sorting-based deduplication would be shorter but would lose the input order, so this keeps a set of values seen so far instead. - `make test` on this branch reports one failure, `TestNowUnixMicro`. That test already fails on `master` and is unrelated to this change: it compares a nanosecond-precision timestamp against one that has been rounded to microseconds. Model: opus-5
clawbot self-assigned this 2026-09-05 05:23:45 +02:00
clawbot added 1 commit 2026-09-05 05:23:45 +02:00
DedupeStrings returns a new slice holding each value once, in the order each
value first appeared, and leaves the input slice alone. Comes with a doc
comment and table-driven tests. (closes #1)

Model: opus-5
sneak merged commit 0183d1a782 into master 2026-09-05 05:46:19 +02:00
Sign in to join this conversation.
No Reviewers
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: sneak/util#2