-
Notifications
You must be signed in to change notification settings - Fork 0
/
collection.go
46 lines (44 loc) · 1.64 KB
/
collection.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
package collection
import (
"encoding/json"
"fmt"
"github.com/carter-ya/go-tools/stream"
)
type Collection[E comparable] interface {
fmt.Stringer
json.Marshaler
json.Unmarshaler
// Add adds an element to the collection.
// Returns true if the element was added.
Add(e E) bool
// AddAll adds all elements from the collection to the collection.
// Returns true if the collection was modified.
AddAll(other Collection[E]) bool
// Remove removes an element from the collection.
Remove(e E) bool
// RemoveAll removes all elements from the collection.
RemoveAll(other Collection[E]) bool
// RemoveIf removes all elements that satisfy the predicate.
RemoveIf(predicate func(e E) bool)
// RetainAll retains only the elements in the collection that are contained in the specified collection.
RetainAll(other Collection[E])
// Clear removes all elements from the collection.
Clear()
// Contains returns true if the collection contains the element.
Contains(e E) bool
// ContainsAll returns true if the collection contains all elements in the specified collection.
ContainsAll(other Collection[E]) bool
// IsEmpty returns true if the collection is empty.
IsEmpty() bool
// Size returns the number of elements in the collection.
Size() int
// ForEach iterates over all elements in the collection.
ForEach(consumer func(e E))
// ForEachIndexed iterates over all elements in the collection.
// The consumer function returns true to stop iterating.
ForEachIndexed(consumer func(index int, e E) (stop bool))
// AsSlice returns the collection as a slice.
AsSlice() []E
// Stream returns a stream of the elements in the collection.
Stream() stream.Stream
}