iter

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2023 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

View Source
const OutOfBounds = "out of bounds"

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]) util.Opt[T]

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[util.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]) util.Opt[T]

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]) util.Opt[T]

Return the last element.

func Max

func Max[T constraints.Ordered](it Iterator[T]) util.Opt[T]

Return the maximum value of all elements of the iterator.

func MaxBy

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

Return the maximum value of all elements of the iterator.

func Min

func Min[T constraints.Ordered](it Iterator[T]) util.Opt[T]

Return the minimum value of all elements of the iterator.

func MinBy

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

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]) util.Opt[T]

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[util.Pair[A, B]]) util.Pair[[]A, []B]

Splitting an iterator whose elements are pair into two lists.

Types

type Collection

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

	Count() int
}

Iterable's extended interfaces, can provide more information to optimize performance.

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 {
	Iterator() Iterator[T]
}

Iterator can be obtained iteratively through Iter, and each iterator should be independent.

type Iterator

type Iterator[T any] interface {
	Next() util.Opt[T]
}

By implementing Next you can perform iterations and end them when the return value is None.

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[util.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 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 Zip

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

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

type Range

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

func RangeOf

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

Constructing an Range with the begin and end.

func (Range[T]) Get

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

Return the begin value and end value.

func (Range[T]) Has

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

Return the index is in range.

func (Range[T]) Iterator

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

type Slice

type Slice[T any] []T

Collection is implemented via Slice, which is isomorphic to the built-in slice.

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

Collection is implemented via String, which is isomorphic to the built-in 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