Files
cloudsave/pkg/tools/iterator/iterator.go
Aurélie DELHAIE 57fc77755e
Some checks failed
CloudSave/pipeline/head There was a failure building this commit
wip
2025-09-12 01:39:47 +02:00

41 lines
548 B
Go

package iterator
type (
Iterator[T any] struct {
index int
values []T
}
)
func New[T any](values []T) *Iterator[T] {
return &Iterator[T]{
values: values,
}
}
func (it *Iterator[T]) Next() bool {
if len(it.values) == it.index {
return false
}
it.index += 1
return true
}
func (it *Iterator[T]) Value() T {
if len(it.values) == 0 {
var zero T
return zero
}
if len(it.values) == it.index {
var zero T
return zero
}
return it.values[it.index]
}
func (it *Iterator[T]) IsEmpty() bool {
return len(it.values) == 0
}