pull

package
v0.0.37 Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2024 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AllMatch

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

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

func AnyMatch

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

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

func At

func At[T any](it Iterator[T], index int) (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](it Iterator[T], collector Collector[S, T, R]) R

Collecting via Collector.

func Contains

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

Returns true if the target is included in the iterator.

func Count

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

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](it Iterator[T], initial R, operation func(R, T) R) R

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

func ForEach

func ForEach[T any](it Iterator[T], action func(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](it Iterator[T]) bool

Ruturns true if the count of Iterator is 0.

func IsNotEmpty

func IsNotEmpty[T any](it Iterator[T]) bool

Ruturns true if the count of Iterator 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](it Iterator[T], greater cmp.LessFunc[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](it Iterator[T], less cmp.LessFunc[T]) (T, bool)

Return the minimum value of all elements of the iterator.

func NoneMatch

func NoneMatch[T any](it Iterator[T], predicate func(T) bool) 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](it Iterator[T], operation func(T, T) 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 ToMap

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

to built-in map.

func ToSlice

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

Converts a Iterator to a Slice.

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 BiFunction

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

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

type BinaryOperator

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

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

type Collector

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

type Comparator

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

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

type Consumer

type Consumer[T any] func(T)

Consumer 消费一个元素

type Function

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

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

type IterStream

type IterStream[T any] struct {
	// contains filtered or unexported fields
}

func SliceStreamOf

func SliceStreamOf[S ~[]T, T any](source S) *IterStream[T]

func StreamOf

func StreamOf[T any](iter Iterator[T]) *IterStream[T]

func (*IterStream[T]) All

func (it *IterStream[T]) All(f func(T) bool) bool

func (*IterStream[T]) Any

func (it *IterStream[T]) Any(f func(T) bool) bool

func (*IterStream[T]) Count

func (it *IterStream[T]) Count() uint64

func (*IterStream[T]) Filter

func (it *IterStream[T]) Filter(f func(T) bool) *IterStream[T]

func (*IterStream[T]) Fold

func (it *IterStream[T]) Fold(initVal T, operation func(T, T) T) T

func (*IterStream[T]) ForEach

func (it *IterStream[T]) ForEach(f func(T))

func (*IterStream[T]) Limit

func (it *IterStream[T]) Limit(n int) *IterStream[T]

func (*IterStream[T]) Map

func (it *IterStream[T]) Map(transform func(T) T) *IterStream[T]

func (*IterStream[T]) None

func (it *IterStream[T]) None(f func(T) bool) bool

func (*IterStream[T]) Reduce

func (it *IterStream[T]) Reduce(operation func(T, T) T) (T, bool)

func (*IterStream[T]) Skip

func (it *IterStream[T]) Skip(n int) *IterStream[T]

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](it Iterator[T], predicate func(T) bool) 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](it Iterator[T], count int) Iterator[T]

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

func Map

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

Use transform to map an iterator to another iterator.

func Range

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

RangeIterOf returns an Iterator over a range of integers.

func Skip

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

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

func Slice

func Slice[S ~[]T, T any](source S) Iterator[T]

func Step

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

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

func String

func String(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 Predicate

type Predicate[T any] func(T) bool

Predicate 断言是否满足指定条件

type Stream

type Stream[T any] interface {
	Filter(Predicate[T]) Stream[T]
	Map(Function[T, T]) Stream[T]               //同类型转换,没啥意义
	FlatMap(Function[T, Iterator[T]]) Stream[T] //同Map
	Peek(Consumer[T]) Stream[T]
	Fold(initVal T, acc BinaryOperator[T])
	Zip(Iterator[T], Iterator[T]) Stream[T]

	Distinct(Function[T, int]) Stream[T]
	Sorted(Comparator[T]) Stream[T]
	Limit(int64) Stream[T]
	Skip(int64) Stream[T]

	ForEach(Consumer[T])
	Collect() []T
	All(Predicate[T]) bool
	None(Predicate[T]) bool
	Any(Predicate[T]) bool
	Reduce(acc BinaryOperator[T]) (T, bool)
	ReduceFrom(initVal T, acc BinaryOperator[T]) T
	First() (T, bool)
	Count() int64
}

type Supplier

type Supplier[T any] func() T

Supplier 产生一个元素

type UnaryOperator

type UnaryOperator[T any] func(T) T

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

Jump to

Keyboard shortcuts

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