/
id_list.go
43 lines (35 loc) · 1.05 KB
/
id_list.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
package report
// IDList is a list of string IDs, which are always sorted and unique.
type IDList StringSet
var emptyIDList = IDList(MakeStringSet())
// MakeIDList makes a new IDList.
func MakeIDList(ids ...string) IDList {
if len(ids) == 0 {
return emptyIDList
}
return IDList(MakeStringSet(ids...))
}
// Add is the only correct way to add ids to an IDList.
func (a IDList) Add(ids ...string) IDList {
if len(ids) == 0 {
return a
}
return IDList(StringSet(a).Add(ids...))
}
// Merge all elements from a and b into a new list
func (a IDList) Merge(b IDList) IDList {
merged, _ := StringSet(a).Merge(StringSet(b))
return IDList(merged)
}
// Equal returns true if a and b have the same contents
func (a IDList) Equal(b IDList) bool {
return StringSet(a).Equal(StringSet(b))
}
// Contains returns true if id is in the list.
func (a IDList) Contains(id string) bool {
return StringSet(a).Contains(id)
}
// Intersection returns the intersection of a and b
func (a IDList) Intersection(b IDList) IDList {
return IDList(StringSet(a).Intersection(StringSet(b)))
}