-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfunction_seq.go
More file actions
31 lines (27 loc) · 884 Bytes
/
function_seq.go
File metadata and controls
31 lines (27 loc) · 884 Bytes
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
package gogcoll
// functionSeq is a generic Seq implementation that uses function fields
// for the Next and HasNext functionalities, to make it easier to create
// small Seq implementations.
type functionSeq[T any] struct {
baseSeq[T]
next FixedFunction[T]
hasNext FixedFunction[bool]
}
// createFunctionSequence takes functions for Next and HasNext and returns a Seq that will
// use the given functions to implement the full Seq functionality.
func createFunctionSequence[T any](next FixedFunction[T], hasNext FixedFunction[bool]) Seq[T] {
fs := &functionSeq[T]{
next: next,
hasNext: hasNext,
}
fs.self = fs
return fs
}
// Next is part of the implementation of the Seq interface
func (s *functionSeq[T]) Next() T {
return s.next()
}
// HasNext is part of the implementation of the Seq interface
func (s *functionSeq[T]) HasNext() bool {
return s.hasNext()
}