-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathset.go
67 lines (58 loc) · 1.24 KB
/
set.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package oper
import "github.com/spf13/cast"
func Set(fat interface{}) (sub interface{}) {
var subs []string
fats := cast.ToStringSlice(fat)
maps := make(map[string]bool)
for _, v := range fats {
if !maps[v] {
maps[v] = true
subs = append(subs, v)
}
}
return subs
}
func Add(fat interface{}, value interface{}) (sub interface{}) {
var subs []string
fats := cast.ToStringSlice(fat)
va := cast.ToString(value)
maps := make(map[string]bool)
fats = append(fats, va)
for _, v := range fats {
if !maps[v] {
maps[v] = true
subs = append(subs, v)
}
}
return subs
}
func Union(fat interface{}, set ...interface{}) (sub interface{}) {
var subs []string
fats := cast.ToStringSlice(fat)
for _, v := range set {
sets := cast.ToStringSlice(v)
fats = append(fats, sets...)
}
maps := make(map[string]bool)
for _, v := range fats {
if !maps[v] {
maps[v] = true
subs = append(subs, v)
}
}
return subs
}
func Update(fat interface{}, set interface{}) (sub interface{}) {
var subs []string
fats := cast.ToStringSlice(fat)
sets := cast.ToStringSlice(set)
fats = append(fats, sets...)
maps := make(map[string]bool)
for _, v := range fats {
if !maps[v] {
maps[v] = true
subs = append(subs, v)
}
}
return subs
}