iter

package
v0.1.12 Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AllMatch added in v0.1.0

func AllMatch[T any](seq iter.Seq[T], test funcs.Predicate[T]) bool

AllMatch test if every elements are all match the Predicate. 是否每个元素都满足条件

func AnyMatch added in v0.1.0

func AnyMatch[T any](seq iter.Seq[T], test funcs.Predicate[T]) bool

AnyMatch test if any element matches the Predicate. 是否有任意元素满足条件

func At added in v0.1.12

func At[T any](it iter.Seq[T], index int) (T, bool)

Return the element at index.

func Average added in v0.1.12

func Average[T constraintsi.Number](it iter.Seq[T]) T

Returns the average of all the elements in the iterator.

func Chain added in v0.1.12

func Chain[T any](seqs ...iter.Seq[T]) iter.Seq[T]

func ChannelAll2

func ChannelAll2[T any](c chan T) iter.Seq2[int, T]

func Collect added in v0.1.0

func Collect[T any, S any, R any](it iter.Seq[T], collector interfaces.Collector[S, T, R]) R

Collecting via Collector.

func Contains added in v0.1.12

func Contains[T comparable](it iter.Seq[T], target T) bool

Returns true if the target is included in the iterator.

func Count added in v0.1.0

func Count[T any](seq iter.Seq[T]) (count int)

Count return the count of elements in the Seq. 返回序列中的元素个数

func Distinct added in v0.1.0

func Distinct[T any, C comparable](seq iter.Seq[T], f funcs.UnaryFunction[T, C]) iter.Seq[T]

Distinct remove duplicate elements. 对序列中的元素去重

func Enumerate added in v0.1.0

func Enumerate[T any](seq iter.Seq[T]) iter.Seq[types.Pair[int, T]]

func Filter added in v0.1.0

func Filter[T any](seq iter.Seq[T], test funcs.Predicate[T]) iter.Seq[T]

Filter keep elements which satisfy the Predicate. 保留满足断言的元素

func First added in v0.1.0

func First[T any](seq iter.Seq[T]) (T, bool)

First find the first element in the Seq. 返回序列中的第一个元素(如有).

func FlatMap added in v0.1.0

func FlatMap[T, R any](seq iter.Seq[T], flatten funcs.UnaryFunction[T, iter.Seq[R]]) iter.Seq[R]

FlatMap transform each element in Seq[T] to a new Seq[R]. 将原本序列中的每个元素都转换为一个新的序列, 并将所有转换后的序列依次连接起来生成一个新的序列

func Fold added in v0.1.0

func Fold[T, R any](seq iter.Seq[T], initVal R, acc funcs.BinaryFunction[R, T, R]) (result R)

Fold accumulate each element using the BinaryFunction starting from the initial value. 从初始值开始, 通过 acc 函数累加每个元素

func ForEach added in v0.1.0

func ForEach[T any](seq iter.Seq[T], accept funcs.Consumer[T])

ForEach consume every elements in the Seq. 消费序列中的每个元素

func IsEmpty added in v0.1.12

func IsEmpty[T any](it iter.Seq[T]) bool

Ruturns true if the count of Iterator is 0.

func IsNotEmpty added in v0.1.12

func IsNotEmpty[T any](it iter.Seq[T]) bool

Ruturns true if the count of Iterator is 0.

func IsSorted added in v0.1.0

func IsSorted[T any](seq iter.Seq[T], cmp funcs.Comparator[T]) bool

IsSorted 对序列中的元素是否排序

func IterSeq added in v0.1.12

func IterSeq[T any](iter Iterator[T]) iter2.Seq[T]

func Last added in v0.1.12

func Last[T any](it iter.Seq[T]) (T, bool)

Return the right element.

func Limit added in v0.1.0

func Limit[T any](seq iter.Seq[T], limit int) iter.Seq[T]

Limit limits the number of elements in Seq. 限制元素个数

func Map added in v0.1.0

func Map[T, R any](seq iter.Seq[T], f funcs.UnaryFunction[T, R]) iter.Seq[R]

Map transform the element use Fuction. 使用输入函数对每个元素进行转换

func Max added in v0.1.12

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

Return the maximum value of all elements of the iterator.

func MaxBy added in v0.1.12

func MaxBy[T any](it iter.Seq[T], greater cmp.LessFunc[T]) (T, bool)

Return the maximum value of all elements of the iterator.

func Min added in v0.1.12

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

Return the minimum value of all elements of the iterator.

func NoneMatch added in v0.1.0

func NoneMatch[T any](seq iter.Seq[T], test funcs.Predicate[T]) bool

NoneMatch test if none element matches the Predicate. 是否没有元素满足条件

func Operator added in v0.1.12

func Operator[T any](seq iter.Seq[T], add funcs.BinaryOperator[T]) T

func OperatorBy added in v0.1.12

func OperatorBy[T any](it iter.Seq[T], f funcs.BinaryOperator[T]) T

func Peek added in v0.1.0

func Peek[T any](seq iter.Seq[T], accept funcs.Consumer[T]) iter.Seq[T]

Peek visit every element in the Seq and leave them on the Seq. 访问序列中的每个元素而不消费它

func Product added in v0.1.12

func Product[T constraintsi.Number](it iter.Seq[T]) T

Returns the product of all the elements in the iterator.

func RangeAll2

func RangeAll2[T constraintsi.Number](begin, end, step T) iter.Seq2[int, T]

func Reduce added in v0.1.0

func Reduce[T any](seq iter.Seq[T], acc funcs.BinaryOperator[T]) (T, bool)

Reduce accumulate each element using the binary operation. 使用给定的累加函数, 累加序列中的每个元素. 序列中可能没有元素因此返回的是 Optional

func Seq2Keys added in v0.1.1

func Seq2Keys[K, V any](s iter.Seq2[K, V]) iter.Seq[K]

func Seq2Seq

func Seq2Seq[K, V any](s iter.Seq2[K, V]) iter.Seq[types.Pair[K, V]]

func Seq2Values added in v0.1.1

func Seq2Values[K, V any](s iter.Seq2[K, V]) iter.Seq[V]

func SeqSeq2 added in v0.1.0

func SeqSeq2[T any](seq iter.Seq[T]) iter.Seq2[int, T]

func Skip added in v0.1.0

func Skip[T any](seq iter.Seq[T], skip int) iter.Seq[T]

Skip drop some elements of the Seq. 跳过指定个数的元素

func Sorted added in v0.1.0

func Sorted[T any](it iter.Seq[T], cmp funcs.Comparator[T]) iter.Seq[T]

Sorted sort elements in the Seq by Comparator. 对序列中的元素排序

func StringAll2

func StringAll2(input string) iter.Seq2[int, rune]

func Sum added in v0.1.10

func Sum[T constraintsi.Number](it iter.Seq[T]) T

Returns the sum of all the elements in the iterator.

func SumComparable added in v0.1.10

func SumComparable[T constraints.Ordered](seq iter.Seq[T]) T

func ToMap added in v0.1.12

func ToMap[K comparable, V any](it iter.Seq[types.Pair[K, V]]) map[K]V

to built-in map.

func Until added in v0.1.10

func Until[T any](seq iter.Seq[T], match funcs.Predicate[T]) iter.Seq[T]

func UntilComparable added in v0.1.10

func UntilComparable[T comparable](seq iter.Seq[T], e T) iter.Seq[T]

func Unzip added in v0.1.12

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

Splitting an iterator whose elements are pair into two lists.

Types

type GoIter added in v0.1.12

type GoIter[T any] interface {
	Iterator[T]
	Stop()
}

type Iterable added in v0.1.12

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

type Iterator added in v0.1.12

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

func SeqIter added in v0.1.12

func SeqIter[T any](seq iter2.Seq[T]) Iterator[T]

type Seq added in v0.1.0

type Seq[T any] iter.Seq[T]

func ChannelAll added in v0.1.0

func ChannelAll[T any](c chan T) Seq[T]

func HashMapAll added in v0.1.0

func HashMapAll[K comparable, V any](m map[K]V) Seq[types.Pair[K, V]]

func RangeAll added in v0.1.0

func RangeAll[T constraintsi.Number](begin, end, step T) Seq[T]

func SliceAll added in v0.1.0

func SliceAll[T any](input []T) Seq[types.Pair[int, T]]

func SliceBackward added in v0.1.0

func SliceBackward[T any](input []T) Seq[types.Pair[int, T]]

func SliceBackwardValues added in v0.1.1

func SliceBackwardValues[T any](input []T) Seq[T]

func StringAll added in v0.1.0

func StringAll(input string) Seq[types.Pair[int, rune]]

func StringRunes added in v0.1.1

func StringRunes(input string) Seq[rune]

func (Seq[T]) All added in v0.1.0

func (it Seq[T]) All(test funcs.Predicate[T]) bool

func (Seq[T]) Any added in v0.1.0

func (it Seq[T]) Any(test funcs.Predicate[T]) bool

func (Seq[T]) Collect added in v0.1.0

func (it Seq[T]) Collect() []T

func (Seq[T]) Count added in v0.1.0

func (it Seq[T]) Count() int

func (Seq[T]) Distinct added in v0.1.0

func (it Seq[T]) Distinct(f funcs.UnaryFunction[T, int]) Stream[T]

func (Seq[T]) Filter added in v0.1.0

func (it Seq[T]) Filter(test funcs.Predicate[T]) Stream[T]

func (Seq[T]) First added in v0.1.0

func (it Seq[T]) First() (T, bool)

func (Seq[T]) FlatMap added in v0.1.0

func (it Seq[T]) FlatMap(f funcs.UnaryFunction[T, iter.Seq[T]]) Stream[T]

func (Seq[T]) Fold added in v0.1.0

func (it Seq[T]) Fold(initVal T, acc funcs.BinaryOperator[T]) T

func (Seq[T]) ForEach added in v0.1.0

func (it Seq[T]) ForEach(accept funcs.Consumer[T])

func (Seq[T]) IsSorted added in v0.1.0

func (it Seq[T]) IsSorted(cmp funcs.Comparator[T]) bool

func (Seq[T]) Iter added in v0.1.0

func (it Seq[T]) Iter() Iterator[T]

func (Seq[T]) Limit added in v0.1.0

func (it Seq[T]) Limit(limit int) Stream[T]

func (Seq[T]) Map added in v0.1.0

func (it Seq[T]) Map(f funcs.UnaryFunction[T, T]) Stream[T]

func (Seq[T]) None added in v0.1.0

func (it Seq[T]) None(test funcs.Predicate[T]) bool

func (Seq[T]) Peek added in v0.1.0

func (it Seq[T]) Peek(accept funcs.Consumer[T]) Stream[T]

func (Seq[T]) Reduce added in v0.1.0

func (it Seq[T]) Reduce(acc funcs.BinaryOperator[T]) (T, bool)

func (Seq[T]) Seq added in v0.1.0

func (it Seq[T]) Seq() iter.Seq[T]

func (Seq[T]) Skip added in v0.1.0

func (it Seq[T]) Skip(skip int) Stream[T]

func (Seq[T]) Sorted added in v0.1.0

func (it Seq[T]) Sorted(cmp funcs.Comparator[T]) Stream[T]

func (Seq[T]) Sum added in v0.1.10

func (it Seq[T]) Sum(add funcs.BinaryOperator[T]) T

func (Seq[T]) Until added in v0.1.10

func (it Seq[T]) Until(test funcs.Predicate[T]) Stream[T]

type Stream added in v0.1.0

type Stream[T any] interface {
	Seq() iter.Seq[T]

	Filter(funcs.Predicate[T]) Stream[T]
	Map(funcs.UnaryFunction[T, T]) Stream[T]               //同类型转换,没啥意义
	FlatMap(funcs.UnaryFunction[T, iter.Seq[T]]) Stream[T] //同Map
	Peek(funcs.Consumer[T]) Stream[T]
	Sorted(funcs.Comparator[T]) Stream[T]
	Distinct(funcs.UnaryFunction[T, int]) Stream[T]
	Limit(int) Stream[T]
	Until(funcs.Predicate[T]) Stream[T]
	Skip(int) Stream[T]

	ForEach(funcs.Consumer[T])
	Collect() []T
	IsSorted(funcs.Comparator[T]) bool
	All(funcs.Predicate[T]) bool // every
	None(funcs.Predicate[T]) bool
	Any(funcs.Predicate[T]) bool // some
	Reduce(acc funcs.BinaryOperator[T]) (T, bool)
	Fold(initVal T, acc funcs.BinaryOperator[T]) T
	First() (T, bool)
	Count() int
	Sum(funcs.BinaryOperator[T]) T
}

func StreamOf added in v0.1.1

func StreamOf[T any](seq iter.Seq[T]) Stream[T]

Jump to

Keyboard shortcuts

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