-
Notifications
You must be signed in to change notification settings - Fork 1
/
tee.go
29 lines (23 loc) · 657 Bytes
/
tee.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
package ranges
type teeResult[T any] struct {
input InputRange[T]
output OutputRange[T]
}
func (tr *teeResult[T]) Empty() bool {
return tr.input.Empty()
}
func (tr *teeResult[T]) Front() T {
return tr.input.Front()
}
func (tr *teeResult[T]) PopFront() {
tr.output.Put(tr.input.Front())
tr.input.PopFront()
}
// Tee produces a range that outputs to a given 'output' when elements are popped.
func Tee[T any](r InputRange[T], output OutputRange[T]) InputRange[T] {
return &teeResult[T]{r, output}
}
// TeeS is `Tee` accepting a slice.
func TeeS[T any](r []T, output OutputRange[T]) InputRange[T] {
return &teeResult[T]{SliceRange(r), output}
}