Documentation
¶
Index ¶
- Variables
- func DoIterator[T any](iterator Iterator[T], iteratorFunc func(value T) bool)
- func IsIterator[T any](structObject any) bool
- func ToChannel[T any](iterator Iterator[T]) chan T
- func ToSlice[T any](iterator Iterator[T]) []T
- type ChainIterator
- type ChannelIterator
- type CycleIterator
- type Iterable
- type Iterator
- type IteratorWithIndex
- type IteratorWithKey
- type MapEntry
- type MapIterator
- type RangeIterator
- type ReverseIteratorWithIndex
- type ReverseIteratorWithKey
- type SliceIterator
Constants ¶
This section is empty.
Variables ¶
View Source
var ErrIsNotIterator = errors.New("is not iterator")
Functions ¶
func DoIterator ¶
DoIterator 遍历一个迭代器
Types ¶
type ChainIterator ¶
type ChainIterator[T any] struct { // contains filtered or unexported fields }
ChainIterator 把多个迭代器组合为一个迭代器,
func NewChainIterator ¶
func NewChainIterator[T any](iterators ...Iterator[T]) *ChainIterator[T]
func (*ChainIterator[T]) Next ¶
func (x *ChainIterator[T]) Next() bool
func (*ChainIterator[T]) Value ¶
func (x *ChainIterator[T]) Value() T
type ChannelIterator ¶
type ChannelIterator[T any] struct { // contains filtered or unexported fields }
ChannelIterator 用于把一个channel封装为iterator
func NewChannelIterator ¶
func NewChannelIterator[T any](channel <-chan T) *ChannelIterator[T]
func (*ChannelIterator[T]) Next ¶
func (x *ChannelIterator[T]) Next() bool
func (*ChannelIterator[T]) Value ¶
func (x *ChannelIterator[T]) Value() T
type CycleIterator ¶
type CycleIterator[T any] struct { // contains filtered or unexported fields }
CycleIterator 把一个给定的序列无限循环
func NewCycleIterator ¶
func NewCycleIterator[T any](slice ...T) *CycleIterator[T]
func (*CycleIterator[T]) Next ¶
func (x *CycleIterator[T]) Next() bool
func (*CycleIterator[T]) Value ¶
func (x *CycleIterator[T]) Value() T
type Iterator ¶
type Iterator[T any] interface { // Next 将迭代器的指针往后移动一个,同时返回指针当前指向的位置是否有元素 Next() bool // Value 返回指针指向的元素,如果没有元素的话返回对应类型的零值 Value() T }
Iterator 表示一个迭代器,迭代器的元素类型是T
func CastToIterator ¶
CastToIterator 转换为迭代器
func FromChannel ¶
type IteratorWithIndex ¶
type IteratorWithKey ¶
type MapIterator ¶
type MapIterator[K comparable, V any] struct { // contains filtered or unexported fields }
MapIterator 用于遍历一个Map的迭代器
func NewMapIterator ¶
func NewMapIterator[K comparable, V any](m map[K]V) *MapIterator[K, V]
func (*MapIterator[K, V]) Next ¶
func (x *MapIterator[K, V]) Next() bool
func (*MapIterator[K, V]) Value ¶
func (x *MapIterator[K, V]) Value() *MapEntry[K, V]
type RangeIterator ¶
type RangeIterator struct {
// contains filtered or unexported fields
}
RangeIterator 范围递增的迭代器
func NewRangeIterator ¶
func NewRangeIterator(begin, end int) *RangeIterator
NewRangeIterator [begin, end)的左闭右开区间
func (*RangeIterator) Next ¶
func (x *RangeIterator) Next() bool
func (*RangeIterator) Value ¶
func (x *RangeIterator) Value() int
type ReverseIteratorWithKey ¶
type SliceIterator ¶
type SliceIterator[T any] struct { // contains filtered or unexported fields }
SliceIterator 用于把切片封装为迭代器
func NewSliceIterator ¶
func NewSliceIterator[T any](slice []T) *SliceIterator[T]
func (*SliceIterator[T]) Next ¶
func (x *SliceIterator[T]) Next() bool
func (*SliceIterator[T]) Value ¶
func (x *SliceIterator[T]) Value() T
Click to show internal directories.
Click to hide internal directories.