@@ -25,33 +25,10 @@ import (
2525 "github.com/spf13/cobra"
2626)
2727
28- // // TODO: When update to go 1.18 or later, convert to generic
29- // // to allow uniquify() on any slice that supports
30- // // `comparable`
31- // // See https://gosamples.dev/generics-remove-duplicates-slice/
32- // func uniquify[T comparable](s []T) []T {
33- // // use a map, which enforces unique keys
34- // inResult := make(map[T]bool)
35- // var result []T
36- // // loop through input slice **in order**,
37- // // to ensure output retains that order
38- // // (except that it removes duplicates)
39- // for i := 0; i < len(s); i++ {
40- // // attempt to use the element as a key
41- // if _, ok := inResult[s[i]]; !ok {
42- // // if key didn't exist in map,
43- // // add to map and append to result
44- // inResult[s[i]] = true
45- // result = append(result, s[i])
46- // }
47- // }
48- // return result
49- // }
50-
51- func uniquifyStringSlice (s []string ) []string {
28+ func uniquify [T comparable ](s []T ) []T {
5229 // use a map, which enforces unique keys
53- inResult := make (map [string ]bool )
54- var result []string
30+ inResult := make (map [T ]bool )
31+ var result []T
5532 // loop through input slice **in order**,
5633 // to ensure output retains that order
5734 // (except that it removes duplicates)
@@ -96,7 +73,7 @@ func runAddCommand(cmd *cobra.Command, args []string) {
9673
9774 v := configuration .Settings .GetStringSlice (key )
9875 v = append (v , args [1 :]... )
99- v = uniquifyStringSlice (v )
76+ v = uniquify (v )
10077 configuration .Settings .Set (key , v )
10178
10279 if err := configuration .Settings .WriteConfig (); err != nil {
0 commit comments