forked from nyaruka/goflow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
slices.go
78 lines (62 loc) · 1.77 KB
/
slices.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
68
69
70
71
72
73
74
75
76
77
78
package mobile
// Because gomobile currently only supports slices of bytes
// StringSlice wraps a slice of strings
type StringSlice struct {
items []string
}
// NewStringSlice creates a new string list
func NewStringSlice(capacity int) *StringSlice {
return &StringSlice{items: make([]string, 0, capacity)}
}
// Add adds an string to this slice
func (l *StringSlice) Add(item string) {
l.items = append(l.items, item)
}
// Length gets the length of this slice
func (l *StringSlice) Length() int {
return len(l.items)
}
// Get returns the string at the given index
func (l *StringSlice) Get(index int) string {
return l.items[index]
}
// EventSlice wraps a slice of events
type EventSlice struct {
items []*Event
}
// NewEventSlice creates a new slice of events
func NewEventSlice(capacity int) *EventSlice {
return &EventSlice{items: make([]*Event, 0, capacity)}
}
// Add adds an event to this slice
func (l *EventSlice) Add(item *Event) {
l.items = append(l.items, item)
}
// Length gets the length of this slice
func (l *EventSlice) Length() int {
return len(l.items)
}
// Get returns the event at the given index
func (l *EventSlice) Get(index int) *Event {
return l.items[index]
}
// ModifierSlice wraps a slice of modifiers
type ModifierSlice struct {
items []*Modifier
}
// NewModifierSlice creates a new slice of modifiers
func NewModifierSlice(capacity int) *ModifierSlice {
return &ModifierSlice{items: make([]*Modifier, 0, capacity)}
}
// Add adds an event to this slice
func (l *ModifierSlice) Add(item *Modifier) {
l.items = append(l.items, item)
}
// Length gets the length of this slice
func (l *ModifierSlice) Length() int {
return len(l.items)
}
// Get returns the event at the given index
func (l *ModifierSlice) Get(index int) *Modifier {
return l.items[index]
}