-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathlinq.go
38 lines (29 loc) · 1.03 KB
/
linq.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
// LINQ for Go with type parameters
package linq
// IEnumerable[T] is a queryable collection.
type IEnumerable[T any] interface {
Enumerable[T] | OrderedEnumerable[T]
}
// Enumerable[T] is an implementation of IEnumerable[T].
type Enumerable[T any] func() Enumerator[T]
// OrderedEnumerable[T] is an implementation of IEnumerable[T], which is generated by OrderBy or ThenBy.
type OrderedEnumerable[T any] func() Enumerator[T]
// Enumerator[T] is an enumerator of the collection.
type Enumerator[T any] interface {
// Next returns a next element of this collection.
// It returns EOC as an `error` when it reaches the end of the collection.
Next() (T, error)
}
// Error : LINQ error type.
type Error string
const (
// EOC : End of the collection.
EOC Error = "End of the collection"
// OutOfRange : Index out of range.
OutOfRange Error = "Out of range"
// InvalidOperation : Invalid operation such as no element satisfying the condition.
InvalidOperation Error = "Invalid operation"
)
func (e Error) Error() string {
return string(e)
}