forked from go/golangs_learn
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
32 lines
453 B
32 lines
453 B
3 years ago
|
package iterator
|
||
|
|
||
|
type Iterator interface {
|
||
|
Index() int
|
||
|
Value() interface{}
|
||
|
HashNext() bool
|
||
|
Next()
|
||
|
}
|
||
|
|
||
|
type ArrayIterator struct {
|
||
|
array []interface{}
|
||
|
index *int
|
||
|
}
|
||
|
|
||
|
func (a *ArrayIterator) Index() *int {
|
||
|
return a.index
|
||
|
}
|
||
|
|
||
|
func (a *ArrayIterator) Value() interface{} {
|
||
|
return a.array[*a.index]
|
||
|
}
|
||
|
|
||
|
func (a *ArrayIterator) HashNext() bool {
|
||
|
return *a.index+1 <= len(a.array)
|
||
|
}
|
||
|
|
||
|
func (a *ArrayIterator) Next() {
|
||
|
if a.HashNext() {
|
||
|
*a.index++
|
||
|
}
|
||
|
}
|