iters

package
v0.0.0-...-ae1ba64 Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2024 License: MIT Imports: 5 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AllMatch

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

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

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

func Count

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

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

func Distinct

func Distinct[T any, Cmp comparable](seq iter.Seq[T], getUniqKey funcs.Function[T, Cmp]) iter.Seq[T]

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

func Filter

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

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

func FlatMap

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

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

func ForEach

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

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

func Limit

func Limit[T any, Number nums.Int](seq iter.Seq[T], limit Number) iter.Seq[T]

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

func Map

func Map[T, R any](seq iter.Seq[T], apply funcs.Function[T, R]) iter.Seq[R]

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

func NoneMatch

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

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

func Peek

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 Reduce

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

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

func Skip

func Skip[T any, Number nums.Int](seq iter.Seq[T], skip Number) iter.Seq[T]

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

func Sorted

func Sorted[T any](seq iter.Seq[T], cmp order.Comparator[T]) iter.Seq[T]

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

func ToSlice

func ToSlice[T any](seq iter.Seq[T]) (result []T)

ToSlice return all elements as a slice. 将序列中所有元素收集为切片返回

Types

type Entry

type Entry[K, V any] struct {
	Key K
	Val V
}

type Seq

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

func Generate

func Generate[T any](get funcs.Supplier[T]) Seq[T]

Generate build a Seq, which each element is generate by the Supplier. 通过生成器生成一个序列

func Of

func Of[T any](elements ...T) Seq[T]

Of build a Seq by input elements. 使用输入的任意个元素创建一个序列

func OfSeq

func OfSeq[T any](s iter.Seq[T]) Seq[T]

OfSeq convert from iter.Seq. 类型转换, 从 iter.Seq 转为 Seq.

func OfSlice

func OfSlice[T any](s []T) Seq[T]

OfSlice build a Seq by input slice. 使用输入的切片创建一个序列

func Range

func Range[T nums.Number](fromInclude, toExclude T) Seq[T]

Range build a Seq count from fromInclude to toExclude. 构造一个左闭右开的升序区间序列

func RangeStep

func RangeStep[T, S nums.Number](fromInclude, toExclude T, step S) Seq[T]

RangeStep build a Seq count from fromInclude to toExclude. step may negetive. 按指定步进大小构造一个左闭右开的序列, 步进大小可以是负数

func Repeat

func Repeat[T any](e T) Seq[T]

Repeat create an infinite Seq, which all elements is same as the input element. 使用输入的单个元素创建一个无限序列

func (Seq[T]) AllMatch

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

func (Seq[T]) AnyMatch

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

func (Seq[T]) Count

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

func (Seq[T]) Distinct

func (it Seq[T]) Distinct(getUniqKey funcs.Function[T, int]) Stream[T]

func (Seq[T]) Filter

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

func (Seq[T]) FlatMap

func (it Seq[T]) FlatMap(flatten funcs.Function[T, iter.Seq[T]]) Stream[T]

func (Seq[T]) ForEach

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

func (Seq[T]) Limit

func (it Seq[T]) Limit(n int64) Stream[T]

func (Seq[T]) Map

func (it Seq[T]) Map(apply funcs.Function[T, T]) Stream[T]

func (Seq[T]) NoneMatch

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

func (Seq[T]) Peek

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

func (Seq[T]) Reduce

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

func (Seq[T]) Seq

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

func (Seq[T]) Seq2

func (it Seq[T]) Seq2() iter.Seq2[int, T]

func (Seq[T]) Skip

func (it Seq[T]) Skip(n int64) Stream[T]

func (Seq[T]) Sorted

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

func (Seq[T]) ToSlice

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

type Seq2

type Seq2[K, V any] iter.Seq2[K, V]

func OfMap

func OfMap[K comparable, V any](m map[K]V) Seq2[K, V]

func OfSlice2

func OfSlice2[T any](s []T) Seq2[int, T]

func (Seq2[K, V]) Entry

func (it Seq2[K, V]) Entry() Seq[Entry[K, V]]

func (Seq2[K, V]) Sorted

func (it Seq2[K, V]) Sorted(cmp order.Comparator[Entry[K, V]]) Seq2[K, V]

type Stream

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

	Filter(test funcs.Predicate[T]) Stream[T]
	Map(apply funcs.Function[T, T]) Stream[T]
	FlatMap(flatten funcs.Function[T, iter.Seq[T]]) Stream[T]
	Peek(accept funcs.Consumer[T]) Stream[T]

	Distinct(getUniqKey funcs.Function[T, int]) Stream[T]
	Sorted(cmp order.Comparator[T]) Stream[T]
	Limit(n int64) Stream[T]
	Skip(n int64) Stream[T]

	Count() int64
	ToSlice() []T
	ForEach(accept funcs.Consumer[T])
	AllMatch(test funcs.Predicate[T]) bool
	AnyMatch(test funcs.Predicate[T]) bool
	NoneMatch(test funcs.Predicate[T]) bool
	Reduce(initVal T, acc funcs.BinaryOperator[T]) T
}

func FlatMaps

func FlatMaps[T, R any](stream Stream[T], flatten funcs.Function[T, iter.Seq[R]]) Stream[R]

FlatMaps is alias of FlatMap. 同 FlatMap, 不过参数是 Stream 而不是 iter.Seq.

func Maps

func Maps[T, R any](stream Stream[T], apply funcs.Function[T, R]) Stream[R]

Maps is alias of Map. 同 Map, 不过参数是 Stream 而不是 iter.Seq.

Jump to

Keyboard shortcuts

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