This repository has been archived by the owner on Jun 9, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
interfaces.go
76 lines (64 loc) · 2.54 KB
/
interfaces.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
package cols
import (
"github.com/djordje200179/extendedlibrary/datastructures/iter"
"github.com/djordje200179/extendedlibrary/misc"
"github.com/djordje200179/extendedlibrary/misc/functions/comparison"
"github.com/djordje200179/extendedlibrary/misc/functions/predication"
)
// Iterator is a special iter.Iterator that can modify the collection it iterates over.
type Iterator[T any] interface {
iter.Iterator[T]
// GetRef returns a reference to the current element.
GetRef() *T
// Set sets the current element to the given value.
Set(value T)
// InsertBefore inserts the given value before the current element.
InsertBefore(value T)
// InsertAfter inserts the given value after the current element.
InsertAfter(value T)
// Remove removes the current element.
Remove()
// Index returns the Index of the current element.
Index() int
}
// Collection is a special iter.Iterable that represents a collection of elements.
type Collection[T any] interface {
// Size returns the number of elements.
Size() int
// Get returns the element at the given index.
Get(index int) T
// GetRef returns a reference to the element at the given Index.
GetRef(index int) *T
// Set sets the element at the given Index to the given value.
Set(index int, value T)
// Prepend prepends the given value to the collection.
Prepend(value T)
// Append appends the given value to the collection.
Append(value T)
// Insert inserts the given value at the given index.
Insert(index int, value T)
// Remove removes the element at the given index.
Remove(index int)
// Clear clears the collection.
Clear()
// Reverse reverses the collection.
Reverse()
// Sort sorts the collection using the given comparator.
Sort(comparator comparison.Comparator[T])
// Join joins the collection with the given collection.
Join(other Collection[T])
misc.Cloner[Collection[T]]
iter.Iterable[T]
// CollectionIterator creates and returns a new Iterator.
CollectionIterator() Iterator[T]
// Stream streams the elements of the Collection.
Stream(yield func(T) bool)
// RefsStream streams references to the elements of the Collection.
RefsStream(yield func(*T) bool)
// FindIndex returns the index of the first element that satisfies the given predicate.
// If no element satisfies the predicate, 0 and false are returned.
FindIndex(predicate predication.Predicate[T]) (int, bool)
// FindRef returns a reference to the first element that satisfies the given predicate.
// If no element satisfies the predicate, nil and false are returned.
FindRef(predicate predication.Predicate[T]) (*T, bool)
}