You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

27 lines
516 B
Go

package iter
import "constraints"
type slice[T any] []T
type sliceIter[T any] struct {
s slice[T]
i int
}
func (it *sliceIter[T]) Next(v *T) bool {
if it.i >= len(it.s) {
return false
}
*v = it.s[it.i]
it.i++
return true
}
func (it *sliceIter[T]) Iter() Ator[T] { return &sliceIter[T]{s: it.s} }
func (s slice[T]) Iter() Ator[T] { return &sliceIter[T]{s: s} }
// Slice takes a slice and returns an iterable backed by that slice
func Slice[T constraints.Integer](s []T) Able[T] { return slice[T](s) }