iterator

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Jun 25, 2022 License: Apache-2.0 Imports: 1 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Reduce

func Reduce[T, U any](iter Nexter[T], reducer func(accumulator U, next T) U, inital U) U

Types

type ChanIter

type ChanIter[T any] struct {
	// contains filtered or unexported fields
}

func FromChannel

func FromChannel[T any](channel <-chan T) *ChanIter[T]

FromChannel makes ChanIter associated with given channel. To convey end of iterator, close passed channel.

func (*ChanIter[T]) Next

func (ci *ChanIter[T]) Next() (next T, ok bool)

Next earns next element from this iterator. Next blocks until internal channel receives.

func (*ChanIter[T]) NextBack

func (ci *ChanIter[T]) NextBack() (next T, ok bool)

NextBack is alias of Next. Reversing ChanIter is no-op.

type DeIterator

type DeIterator[T any] interface {
	Nexter[T]
	NextBacker[T]
}

Doubly ended iterator.

type Excluder

type Excluder[T any] struct {
	// contains filtered or unexported fields
}

func NewExcluder

func NewExcluder[T any](iter DeIterator[T], excluder func(T) bool) Excluder[T]

func (Excluder[T]) Next

func (e Excluder[T]) Next() (next T, ok bool)

func (Excluder[T]) NextBack

func (e Excluder[T]) NextBack() (next T, ok bool)

type IterExcluder

type IterExcluder[T any] interface {
	Exclude(excluder func(T) bool) Excluder[T]
}

type IterMapper

type IterMapper[T, U any] interface {
	Map(mapper func(T) U) Mapper[T, U]
}

type IterReverser

type IterReverser[T any] interface {
	Reverse() Reverser[T]
}

type IterSelector

type IterSelector[T any] interface {
	Select(selector func(T) bool) Selector[T]
}

type IterSkipper

type IterSkipper[T any] interface {
	SkipN() NSkipper[T]
	SkipWhile(skipIf func(T) bool) WhileSkipper[T]
}

type IterTaker

type IterTaker[T any] interface {
	TakeN() NTaker[T]
	TakeWhile(skipIf func(T) bool) WhileTaker[T]
}

type Iterator

type Iterator[T any] struct {
	DeIterator[T]
}

func Map

func Map[T, U any](iter DeIterator[T], mapper func(T) U) Iterator[U]

func (Iterator[T]) Collect

func (iter Iterator[T]) Collect() []T

func (Iterator[T]) Exclude

func (iter Iterator[T]) Exclude(excluder func(T) bool) Iterator[T]

func (Iterator[T]) ForEach

func (iter Iterator[T]) ForEach(each func(T))

func (Iterator[T]) Reverse

func (iter Iterator[T]) Reverse() Iterator[T]

func (Iterator[T]) Select

func (iter Iterator[T]) Select(selector func(T) bool) Iterator[T]

func (Iterator[T]) SkipN

func (iter Iterator[T]) SkipN(n int) Iterator[T]

func (Iterator[T]) SkipWhile

func (iter Iterator[T]) SkipWhile(skipIf func(T) bool) Iterator[T]

func (Iterator[T]) TakeN

func (iter Iterator[T]) TakeN(n int) Iterator[T]

func (Iterator[T]) TakeWhile

func (iter Iterator[T]) TakeWhile(takeIf func(T) bool) Iterator[T]

type Lenner

type Lenner interface {
	Len() int
}

type ListIter

type ListIter[T any] struct {
	// contains filtered or unexported fields
}

func FromList

func FromList[T any](list list.List[T]) *ListIter[T]

FromList makes ListIter from list.List[T]. Range is fixed at the time FromList returns. Mutating passed list outside this iterator may cause undefined behavior.

func (*ListIter[T]) Len

func (li *ListIter[T]) Len() int

func (*ListIter[T]) Next

func (li *ListIter[T]) Next() (next T, ok bool)

func (*ListIter[T]) NextBack

func (li *ListIter[T]) NextBack() (next T, ok bool)

type Mapper

type Mapper[T, U any] struct {
	// contains filtered or unexported fields
}

func (Mapper[T, U]) Next

func (m Mapper[T, U]) Next() (next U, ok bool)

func (Mapper[T, U]) NextBack

func (m Mapper[T, U]) NextBack() (next U, ok bool)

type NSkipper

type NSkipper[T any] struct {
	// contains filtered or unexported fields
}

func NewNSkipper

func NewNSkipper[T any](iter DeIterator[T], n int) *NSkipper[T]

func (*NSkipper[T]) Next

func (s *NSkipper[T]) Next() (next T, ok bool)

func (*NSkipper[T]) NextBack

func (s *NSkipper[T]) NextBack() (next T, ok bool)

type NTaker

type NTaker[T any] struct {
	// contains filtered or unexported fields
}

func NewNTaker

func NewNTaker[T any](iter DeIterator[T], n int) *NTaker[T]

func (*NTaker[T]) Next

func (s *NTaker[T]) Next() (next T, ok bool)

func (*NTaker[T]) NextBack

func (s *NTaker[T]) NextBack() (next T, ok bool)

type NextBacker

type NextBacker[T any] interface {
	NextBack() (next T, ok bool)
}

type Nexter

type Nexter[T any] interface {
	Next() (next T, ok bool)
}

type Reverser

type Reverser[T any] struct {
	// contains filtered or unexported fields
}

func NewReverser

func NewReverser[T any](iter DeIterator[T]) Reverser[T]

func (Reverser[T]) Next

func (rev Reverser[T]) Next() (next T, ok bool)

func (Reverser[T]) NextBack

func (rev Reverser[T]) NextBack() (next T, ok bool)

type Selector

type Selector[T any] struct {
	// contains filtered or unexported fields
}

func NewSelector

func NewSelector[T any](iter DeIterator[T], selector func(T) bool) Selector[T]

func (Selector[T]) Next

func (s Selector[T]) Next() (next T, ok bool)

func (Selector[T]) NextBack

func (s Selector[T]) NextBack() (next T, ok bool)

type SliceIter

type SliceIter[T any] struct {
	// contains filtered or unexported fields
}

func FromSlice

func FromSlice[T any](sl []T) *SliceIter[T]

FromSlice makes SliceIter from []T. Range is fixed at the time FromSlice returns. Mutating passed sl outside this iterator may cause undefined behavior.

func (*SliceIter[T]) Len

func (si *SliceIter[T]) Len() int

func (*SliceIter[T]) Next

func (si *SliceIter[T]) Next() (next T, ok bool)

func (*SliceIter[T]) NextBack

func (si *SliceIter[T]) NextBack() (next T, ok bool)

type WhileSkipper

type WhileSkipper[T any] struct {
	// contains filtered or unexported fields
}

func NewWhileSkipper

func NewWhileSkipper[T any](iter DeIterator[T], skipIf func(T) bool) *WhileSkipper[T]

func (*WhileSkipper[T]) Next

func (s *WhileSkipper[T]) Next() (next T, ok bool)

func (*WhileSkipper[T]) NextBack

func (s *WhileSkipper[T]) NextBack() (next T, ok bool)

type WhileTaker

type WhileTaker[T any] struct {
	// contains filtered or unexported fields
}

func NewWhileTaker

func NewWhileTaker[T any](iter DeIterator[T], takeIf func(T) bool) *WhileTaker[T]

func (*WhileTaker[T]) Next

func (s *WhileTaker[T]) Next() (next T, ok bool)

func (*WhileTaker[T]) NextBack

func (s *WhileTaker[T]) NextBack() (next T, ok bool)

Jump to

Keyboard shortcuts

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