-
Notifications
You must be signed in to change notification settings - Fork 0
/
bool.go
60 lines (53 loc) · 1006 Bytes
/
bool.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
package utils
func NewPtrBool(b bool) *bool {
return &b
}
type SliceOfBool []bool
func (sob SliceOfBool) Unique() []bool {
mob := map[bool]bool{}
for _, b := range sob {
mob[b] = false
}
uniqueSob := []bool{}
for _, b := range sob {
if added, ok := mob[b]; ok && !added {
uniqueSob = append(uniqueSob, b)
mob[b] = true
}
}
return uniqueSob
}
func (sob SliceOfBool) InSlice(t bool) bool {
for _, b := range sob {
if t == b {
return true
}
}
return false
}
type SliceOfPtrBool []*bool
func (sopb SliceOfPtrBool) Unique() []*bool {
mob := map[bool]bool{}
for _, pb := range sopb {
if pb == nil {
continue
}
mob[*pb] = false
}
uniqueSob := []*bool{}
for _, pb := range sopb {
if added, ok := mob[*pb]; ok && !added {
uniqueSob = append(uniqueSob, NewPtrBool(*pb))
mob[*pb] = true
}
}
return uniqueSob
}
func (sopb SliceOfPtrBool) InSlice(t bool) bool {
for _, pb := range sopb {
if pb != nil && t == *pb {
return true
}
}
return false
}