_2_iterator

package
v0.0.0-...-eb36113 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 19, 2023 License: Apache-2.0, MIT Imports: 1 Imported by: 0

README

迭代器模式

迭代器模式用于使用相同方式送代不同类型集合或者隐藏集合类型的具体实现。

可以使用迭代器模式使遍历同时应用迭代策略,如请求新对象、过滤、处理对象等。

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func IteratorPrint

func IteratorPrint(i Iterator)

Types

type Aggregate

type Aggregate interface {
	Iterator() Iterator
}

type Iterator

type Iterator interface {
	First()
	IsDone() bool
	Next() interface{}
}
Example
var aggregate Aggregate
aggregate = NewNumbers(1, 10)

IteratorPrint(aggregate.Iterator())
Output:

1
2
3
4
5
6
7
8
9
10

type Numbers

type Numbers struct {
	// contains filtered or unexported fields
}

func NewNumbers

func NewNumbers(start, end int) *Numbers

func (*Numbers) Iterator

func (n *Numbers) Iterator() Iterator

type NumbersIterator

type NumbersIterator struct {
	// contains filtered or unexported fields
}

func (*NumbersIterator) First

func (i *NumbersIterator) First()

func (*NumbersIterator) IsDone

func (i *NumbersIterator) IsDone() bool

func (*NumbersIterator) Next

func (i *NumbersIterator) Next() interface{}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL