@@ -25,33 +25,10 @@ import (
25
25
"github.com/spf13/cobra"
26
26
)
27
27
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 {
52
29
// 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
55
32
// loop through input slice **in order**,
56
33
// to ensure output retains that order
57
34
// (except that it removes duplicates)
@@ -96,7 +73,7 @@ func runAddCommand(cmd *cobra.Command, args []string) {
96
73
97
74
v := configuration .Settings .GetStringSlice (key )
98
75
v = append (v , args [1 :]... )
99
- v = uniquifyStringSlice (v )
76
+ v = uniquify (v )
100
77
configuration .Settings .Set (key , v )
101
78
102
79
if err := configuration .Settings .WriteConfig (); err != nil {
0 commit comments