iter

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2024 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AllMatch

func AllMatch[T any](predicate func(T) bool, it Iterator[T]) bool

Returns true if all elements in the iterator match the condition.

func AnyMatch

func AnyMatch[T any](predicate func(T) bool, it Iterator[T]) bool

Returns true if any elements in the iterator match the condition.

func At

func At[T any](index int, it Iterator[T]) (T, bool)

Return the element at index.

func Average

Returns the average of all the elements in the iterator.

func Collect

func Collect[T any, S any, R any](collector Collector[S, T, R], it Iterator[T]) R

Collecting via Collector.

func CollectToMap

func CollectToMap[K comparable, V any](it Iterator[types.Pair[K, V]]) map[K]V

Collect to built-in map.

func CollectToSlice

func CollectToSlice[T any](it Iterator[T]) []T

func Contains

func Contains[T comparable](target T, it Iterator[T]) bool

Returns true if the target is included in the iterator.

func Count

func Count[T any](it Iterator[T]) int

Return the total number of iterators.

func First

func First[T any](it Iterator[T]) (T, bool)

Return the first element.

func Fold

func Fold[T any, R any](initial R, operation func(R, T) R, it Iterator[T]) R

Return the value of the final composite, operates on the iterator from back to front.

func ForEach

func ForEach[T any](action func(T), it Iterator[T])

The action is executed for each element of the iterator, and the argument to the action is the element.

func IsEmpty

func IsEmpty[T any](c Collection[T]) bool

Ruturns true if the count of collection is 0.

func IsNotEmpty

func IsNotEmpty[T any](c Collection[T]) bool

Ruturns true if the count of collection is 0.

func Last

func Last[T any](it Iterator[T]) (T, bool)

Return the last element.

func Max

func Max[T constraints.Ordered](it Iterator[T]) (T, bool)

Return the maximum value of all elements of the iterator.

func MaxBy

func MaxBy[T any](greater func(T, T) bool, it Iterator[T]) (T, bool)

Return the maximum value of all elements of the iterator.

func Min

func Min[T constraints.Ordered](it Iterator[T]) (T, bool)

Return the minimum value of all elements of the iterator.

func MinBy

func MinBy[T any](less func(T, T) bool, it Iterator[T]) (T, bool)

Return the minimum value of all elements of the iterator.

func NoneMatch

func NoneMatch[T any](predicate func(T) bool, it Iterator[T]) bool

Returns true if none elements in the iterator match the condition.

func Product

func Product[T constraints.Integer | constraints.Float](it Iterator[T]) T

Returns the product of all the elements in the iterator.

func Reduce

func Reduce[T any](operation func(T, T) T, it Iterator[T]) (T, bool)

Return the value of the final composite, operates on the iterator from front to back.

func Sum

func Sum[T constraints.Integer | constraints.Float](it Iterator[T]) T

Returns the sum of all the elements in the iterator.

func Unzip

func Unzip[A any, B any](it Iterator[types.Pair[A, B]]) ([]A, []B)

Splitting an iterator whose elements are pair into two lists.

Types

type Collection

type Collection[T any] interface {
	Iterable[T]

	Count() int
}

type Collector

type Collector[S any, T any, R any] interface {
	Builder() S
	Append(builder S, element T)
	Finish(builder S) R
}

type Iterable

type Iterable[T any] interface {
	Iter() Iterator[T]
}

type Iterator

type Iterator[T any] interface {
	Next() (v T, ok bool)
}

func Concat

func Concat[T any](left Iterator[T], right Iterator[T]) Iterator[T]

By connecting two iterators in series, the new iterator will iterate over the first iterator before continuing with the second iterator.

func Enumerate

func Enumerate[T any](it Iterator[T]) Iterator[*types.Pair[int, T]]

Add subscripts to the incoming iterators.

func Filter

func Filter[T any](predicate func(T) bool, it Iterator[T]) Iterator[T]

Use predicate to filter an iterator to another iterator。

func Flatten

func Flatten[T Iterable[U], U any](it Iterator[T]) Iterator[U]

Converting a nested iterator to a flat iterator.

func Limit

func Limit[T any](count int, it Iterator[T]) Iterator[T]

Convert an iterator to another iterator that limits the maximum number of iterations.

func Map

func Map[T any, R any](transform func(T) R, it Iterator[T]) Iterator[R]

Use transform to map an iterator to another iterator.

func MapOf

func MapOf[T any, R any](transform func(T) R, iter Iterator[T]) Iterator[R]

func RangeOf

func RangeOf[T constraints.Integer](begin, end, step T) Iterator[T]

Range returns an Iterator over a range of integers.

func Skip

func Skip[T any](count int, it Iterator[T]) Iterator[T]

Converts an iterator to another iterator that skips a specified number of times.

func Step

func Step[T any](count int, it Iterator[T]) Iterator[T]

Converts an iterator to another iterator that skips a specified number of times each time.

func StringOf

func StringOf(input string) Iterator[rune]

String returns an Iterator yielding runes from the supplied string.

func Zip

func Zip[T any, U any](left Iterator[T], right Iterator[U]) Iterator[*types.Pair[T, U]]

Compress two iterators into one iterator. The length is the length of the shortest iterator.

type MapIter

type MapIter[T any, R any] struct {
	// contains filtered or unexported fields
}

func (*MapIter[T, R]) Next

func (a *MapIter[T, R]) Next() (R, bool)

type Range

type Range[T constraints.Integer] struct {
	Begin T
	End   T
}

func (*Range[T]) Get

func (a *Range[T]) Get() (T, T)

func (*Range[T]) Has

func (a *Range[T]) Has(index T) bool

func (*Range[T]) Iterator

func (a *Range[T]) Iterator() Iterator[T]

type Slice

type Slice[T any] []T

func ToSlice

func ToSlice[T any](c Collection[T]) Slice[T]

Converts a collection to a Slice.

func (Slice[T]) Count

func (a Slice[T]) Count() int

func (Slice[T]) Iterator

func (a Slice[T]) Iterator() Iterator[T]

type String

type String string

func (String) Count

func (a String) Count() int

func (String) Iterator

func (a String) Iterator() Iterator[rune]

Jump to

Keyboard shortcuts

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