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

array.go 392 B

2 years ago
123456789101112131415161718192021222324252627
  1. package iterator
  2. type ArrayIterator[T any] struct {
  3. arr []T
  4. index int
  5. }
  6. func (i *ArrayIterator[T]) MoveNext() (T, error) {
  7. if i.index >= len(i.arr) {
  8. var ret T
  9. return ret, ErrNoMoreItem
  10. }
  11. item := i.arr[i.index]
  12. i.index++
  13. return item, nil
  14. }
  15. func (i *ArrayIterator[T]) Close() {
  16. }
  17. func Array[T any](eles ...T) *ArrayIterator[T] {
  18. return &ArrayIterator[T]{
  19. arr: eles,
  20. }
  21. }