iter

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2024 License: MIT Imports: 5 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 Predicate[T]) bool

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

func AllMatch2

func AllMatch2[K, V any](seq iter.Seq2[K, V], test Predicate2[K, V]) bool

func AnyMatch added in v0.1.0

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

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

func AnyMatch2

func AnyMatch2[K, V any](seq iter.Seq2[K, V], test Predicate2[K, V]) bool

func Collect added in v0.1.0

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

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

func Collect2

func Collect2[K, V any](seq iter.Seq2[K, V]) (ks []K, vs []V)

func Count added in v0.1.0

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

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

func Count2

func Count2[K, V any](seq iter.Seq2[K, V]) (count int64)

func CountForEach added in v0.1.0

func CountForEach[T any](seq iter.Seq[T], accept Consumer[T]) (count int64)

func Distinct added in v0.1.0

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

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

func Distinct2

func Distinct2[K, V any, C comparable](seq iter.Seq2[K, V], f Function2[K, V, C]) iter.Seq2[K, V]

func Enumerate added in v0.1.0

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

func Enumerate2

func Enumerate2[K, V any](seq iter.Seq2[K, V]) iter.Seq2[int, types.Pair[K, V]]

func Filter added in v0.1.0

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

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

func Filter2

func Filter2[K, V any](seq iter.Seq2[K, V], test Predicate2[K, V]) iter.Seq2[K, V]

Dont'use please use types.Pair And Seq

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 Function[T, iter.Seq[R]]) iter.Seq[R]

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

func FlatMap2

func FlatMap2[K, V, R any](seq iter.Seq2[K, V], flatten Function2[K, V, iter.Seq[R]]) iter.Seq[R]

func FlatMap3

func FlatMap3[K, V, RK, RV any](seq iter.Seq2[K, V], flatten Function2[K, V, iter.Seq2[RK, RV]]) iter.Seq2[RK, RV]

func Fold added in v0.1.0

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

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

func Fold2

func Fold2[K, V, R any](seq iter.Seq2[K, V], initVal R, acc BiFunction2[R, K, V, R]) (result R)

func Fold3

func Fold3[K, V, RK, RV any](seq iter.Seq2[K, V], initKey RK, initVal RV, acc BiFunction3[RK, RV, K, V, RK, RV]) (resultKey RK, resultVal RV)

func ForEach added in v0.1.0

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

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

func ForEach2

func ForEach2[K, V any](seq iter.Seq2[K, V], accept Consumer2[K, V])

func IsSorted added in v0.1.0

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

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

func IsSorted2

func IsSorted2[K, V any](seq iter.Seq2[K, V], cmp Comparator2[K, V]) bool

func Limit added in v0.1.0

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

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

func Limit2

func Limit2[K, V any, Number constraints.Number](seq iter.Seq2[K, V], limit Number) iter.Seq2[K, V]

func Map added in v0.1.0

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

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

func Map2

func Map2[K, V, R any](seq iter.Seq2[K, V], f Function2[K, V, R]) iter.Seq[R]

func Map3

func Map3[K, V, RK, RV any](seq iter.Seq2[K, V], f Function3[K, V, RK, RV]) iter.Seq2[RK, RV]

func NoneMatch added in v0.1.0

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

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

func NoneMatch2

func NoneMatch2[K, V any](seq iter.Seq2[K, V], test Predicate2[K, V]) bool

func Peek added in v0.1.0

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

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

func Peek2

func Peek2[K, V any](seq iter.Seq2[K, V], accept Consumer2[K, V]) iter.Seq2[K, V]

func Reduce added in v0.1.0

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

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

func Reduce2

func Reduce2[K, V any](seq iter.Seq2[K, V], acc BinaryOperator2[K, V]) (K, V, bool)

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, Number constraints.Number](seq iter.Seq[T], skip Number) iter.Seq[T]

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

func Skip2

func Skip2[K, V any, Number constraints.Number](seq iter.Seq2[K, V], skip Number) iter.Seq2[K, V]

func Sorted added in v0.1.0

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

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

func Sorted2

func Sorted2[K, V any](it iter.Seq2[K, V], cmp Comparator2[K, V]) iter.Seq2[K, V]

func Zip added in v0.1.0

func Zip[T any](seq1 iter.Seq[T], seq2 iter.Seq[T]) iter.Seq[T]

func Zip2

func Zip2[K, V any](seq1 iter.Seq2[K, V], seq2 iter.Seq2[K, V]) iter.Seq2[K, V]

Types

type BiFunction added in v0.1.0

type BiFunction[T, R, U any] func(T, R) U

BiFunction 将两个类型转为第三个类型

type BiFunction2

type BiFunction2[K, V, R, U any] func(K, V, R) U

type BiFunction3

type BiFunction3[K, V, RK, RV, UK, UV any] func(K, V, RK, RV) (UK, UV)

type BinaryOperator added in v0.1.0

type BinaryOperator[T any] func(T, T) T

BinaryOperator 输入两个相同类型的参数,对其做二元运算,返回相同类型的结果

type BinaryOperator2

type BinaryOperator2[K, V any] func(K, V, K, V) (K, V)

type Comparator added in v0.1.0

type Comparator[T any] func(T, T) bool

Comparator 比较两个元素. 第一个元素大于第二个元素时,返回正数; 第一个元素小于第二个元素时,返回负数; 否则返回 0.

type Comparator2

type Comparator2[K, V any] func(K, V, K, V) bool

Comparator 比较两个元素. 第一个元素大于第二个元素时,返回正数; 第一个元素小于第二个元素时,返回负数; 否则返回 0.

type Consumer added in v0.1.0

type Consumer[T any] func(T)

Consumer 消费一个元素

type Consumer2

type Consumer2[K, V any] func(K, V)

Consumer 消费一个元素

type Function added in v0.1.0

type Function[T, R any] func(T) R

Function 将一个类型转为另一个类型

type Function2

type Function2[K, V, R any] func(K, V) R

Function 将一个类型转为另一个类型

type Function3

type Function3[K, V, RK, RV any] func(K, V) (RK, RV)

type Predicate added in v0.1.0

type Predicate[T any] func(T) bool

Predicate 断言是否满足指定条件

type Predicate2

type Predicate2[K, V any] func(K, V) bool

Predicate 断言是否满足指定条件

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 HashMaKeys added in v0.1.1

func HashMaKeys[K comparable, V any](m map[K]V) Seq[K]

func HashMapAll added in v0.1.0

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

func HashMapValues added in v0.1.1

func HashMapValues[K comparable, V any](m map[K]V) Seq[V]

func RangeAll added in v0.1.0

func RangeAll[T constraints.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 SliceValues added in v0.1.1

func SliceValues[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 Predicate[T]) bool

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

func (it Seq[T]) Any(test 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() int64

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

func (it Seq[T]) Distinct(f Function[T, int]) Stream[T]

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

func (it Seq[T]) Filter(test 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 Function[T, iter.Seq[T]]) Stream[T]

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

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

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

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

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

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

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

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

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

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

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

func (it Seq[T]) Map(f Function[T, T]) Stream[T]

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

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

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

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

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

func (it Seq[T]) Reduce(acc 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 int64) Stream[T]

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

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

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

func (it Seq[T]) Zip(seq iter.Seq[T]) Stream[T]

type Seq2

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

func ChannelAll2

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

func HashMapAll2

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

func RangeAll2

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

func SliceAll2

func SliceAll2[T any](input []T) Seq2[int, T]

func SliceBackward2

func SliceBackward2[T any](input []T) Seq2[int, T]

func StringAll2

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

func (Seq2[K, V]) Seq

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

type Stream added in v0.1.0

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

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

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

func StreamOf added in v0.1.1

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

type Stream2

type Stream2[K, V any] interface {
	Seq() iter.Seq[types.Pair[K, V]]
	Seq2() iter.Seq2[K, V]

	Filter(Predicate2[K, V]) Stream2[K, V]
	Map(Function2[K, V, V]) Stream2[K, V]                   //同类型转换,没啥意义
	FlatMap(Function2[K, V, iter.Seq2[K, V]]) Stream2[K, V] //同Map
	Peek(Consumer2[K, V]) Stream2[K, V]

	Distinct(Function2[K, V, int]) Stream2[K, V]
	SortedByKeys(Comparator[K]) Stream2[K, V]
	SortedByValues(Comparator[V]) Stream2[K, V]
	Limit(int64) Stream2[K, V]
	Skip(int64) Stream2[K, V]

	ForEach(Consumer2[K, V])
	Collect() ([]K, []V)
	AllMatch(Predicate2[K, V]) bool
	NoneMatch(Predicate2[K, V]) bool
	AnyMatch(Predicate2[K, V]) bool

	First() (K, V)
	Count() int64
}

type Supplier added in v0.1.0

type Supplier[T any] func() T

Supplier 产生一个元素

type Supplier2

type Supplier2[K, V any] func() (K, V)

Dont'use please use types.Pair And Seq Supplier 产生一个元素

type UnaryOperator added in v0.1.0

type UnaryOperator[T any] func(T) T

UnaryOperator 对输入进行一元运算返回相同类型的结果

type UnaryOperator2

type UnaryOperator2[K, V any] func(K, V) (K, V)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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