forked from flowonyx/runtemplate
/
immutable_int_collection.go
138 lines (101 loc) · 5.59 KB
/
immutable_int_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
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
// Generated from immutable/collection.tpl with Type=int
// options: Comparable:true Numeric:<no value> Integer:true Ordered:true Stringer:true Mutable:disabled
// by runtemplate v3.10.1
// See https://github.com/rickb777/runtemplate/blob/master/BUILTIN.md
package examples
// ImmutableIntSizer defines an interface for sizing methods on int collections.
type ImmutableIntSizer interface {
// IsEmpty tests whether ImmutableIntCollection is empty.
IsEmpty() bool
// NonEmpty tests whether ImmutableIntCollection is empty.
NonEmpty() bool
// Size returns the number of items in the list - an alias of Len().
Size() int
}
// ImmutableIntMkStringer defines an interface for stringer methods on int collections.
type ImmutableIntMkStringer interface {
// String implements the Stringer interface to render the list as a comma-separated string enclosed
// in square brackets.
String() string
// MkString concatenates the values as a string using a supplied separator. No enclosing marks are added.
MkString(sep string) string
// MkString3 concatenates the values as a string, using the prefix, separator and suffix supplied.
MkString3(before, between, after string) string
// implements json.Marshaler interface {
MarshalJSON() ([]byte, error)
// StringList gets a slice of strings that depicts all the elements.
StringList() []string
}
// ImmutableIntCollection defines an interface for common collection methods on int.
type ImmutableIntCollection interface {
ImmutableIntSizer
ImmutableIntMkStringer
// IsSequence returns true for lists and queues.
IsSequence() bool
// IsSet returns false for lists and queues.
IsSet() bool
// ToSlice returns a shallow copy as a plain slice.
ToSlice() []int
// ToInterfaceSlice returns a shallow copy as a slice of arbitrary type.
ToInterfaceSlice() []interface{}
// Exists verifies that one or more elements of ImmutableIntCollection return true for the predicate p.
Exists(p func(int) bool) bool
// Forall verifies that all elements of ImmutableIntCollection return true for the predicate p.
Forall(p func(int) bool) bool
// Foreach iterates over ImmutableIntCollection and executes the function f against each element.
Foreach(f func(int))
// Find returns the first int that returns true for the predicate p.
// False is returned if none match.
Find(p func(int) bool) (int, bool)
// MapToString returns a new []string by transforming every element with function f.
// The resulting slice is the same size as the collection. The collection is not modified.
MapToString(f func(int) string) []string
// MapToInt64 returns a new []int64 by transforming every element with function f.
// The resulting slice is the same size as the collection. The collection is not modified.
MapToInt64(f func(int) int64) []int64
// FlatMapString returns a new []string by transforming every element with function f
// that returns zero or more items in a slice. The resulting slice may have a different size to the
// collection. The collection is not modified.
FlatMapToString(f func(int) []string) []string
// FlatMapInt64 returns a new []int64 by transforming every element with function f
// that returns zero or more items in a slice. The resulting slice may have a different size to the
// collection. The collection is not modified.
FlatMapToInt64(f func(int) []int64) []int64
// Send returns a channel that will send all the elements in order. Can be used with the plumbing code, for example.
// A goroutine is created to send the elements; this only terminates when all the elements have been consumed
Send() <-chan int
// CountBy gives the number elements of ImmutableIntCollection that return true for the predicate p.
CountBy(p func(int) bool) int
// Contains determines whether a given item is already in the collection, returning true if so.
Contains(v int) bool
// ContainsAll determines whether the given items are all in the collection, returning true if so.
ContainsAll(v ...int) bool
// Min returns the minimum value of all the items in the collection. Panics if there are no elements.
Min() int
// Max returns the minimum value of all the items in the collection. Panics if there are no elements.
Max() int
// MinBy returns an element of ImmutableIntCollection containing the minimum value, when compared to other elements
// using a passed func defining ‘less’. In the case of multiple items being equally minimal, the first such
// element is returned. Panics if there are no elements.
MinBy(less func(int, int) bool) int
// MaxBy returns an element of ImmutableIntCollection containing the maximum value, when compared to other elements
// using a passed func defining ‘less’. In the case of multiple items being equally maximal, the first such
// element is returned. Panics if there are no elements.
MaxBy(less func(int, int) bool) int
// Fold aggregates all the values in the collection using a supplied function, starting from some initial value.
Fold(initial int, fn func(int, int) int) int
// Sum returns the sum of all the elements in the collection.
Sum() int
}
// ImmutableIntSequence defines an interface for sequence methods on int.
type ImmutableIntSequence interface {
ImmutableIntCollection
// Head gets the first element in the sequence. Head plus Tail include the whole sequence. Head is the opposite of Last.
Head() int
// HeadOption gets the first element in the sequence, if possible.
HeadOption() (int, bool)
// Last gets the last element in the sequence. Init plus Last include the whole sequence. Last is the opposite of Head.
Last() int
// LastOption gets the last element in the sequence, if possible.
LastOption() (int, bool)
}