stream

package
v1.1.3 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2024 License: Apache-2.0 Imports: 7 Imported by: 5

Documentation

Overview

See: zeromicro/go-zero/core/stream

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Collect added in v1.1.0

func Collect[T any, A any, R any](s Stream[T], collector collectors.Collector[T, A, R]) R

func GoSafe

func GoSafe(fn func())

func GroupingBy added in v1.0.5

func GroupingBy[T any, K string | int | int32 | int64, R any](s Stream[T], keyMapper func(T) K, valueMapper func(T) R, opts ...OptFunc[R]) map[K][]R

func Recover

func Recover(cleanups ...func())

func RequireNonNil added in v1.1.2

func RequireNonNil(obj any)

func RunSafe

func RunSafe(fn func())

Types

type OptFunc added in v1.0.5

type OptFunc[T any] func([]T)

OptFunc 定义操作切片的函数

type Optional

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

func OfOptional added in v1.1.2

func OfOptional[T any](t *T) Optional[T]

func OfOptionalNilable added in v1.1.2

func OfOptionalNilable[T any](t *T) Optional[T]

func (Optional[T]) Get

func (o Optional[T]) Get() (v T, ok bool)

func (Optional[T]) IfPresent

func (o Optional[T]) IfPresent(fn func(T))

func (Optional[T]) IsPresent

func (o Optional[T]) IsPresent() bool

func (Optional[T]) OrElse added in v1.1.2

func (o Optional[T]) OrElse(other T) T

func (Optional[T]) OrElseGet added in v1.1.2

func (o Optional[T]) OrElseGet(fn func() T) T

type Stream

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

func Concat

func Concat[T any](s Stream[T], others ...Stream[T]) Stream[T]

Concat 拼接流

func FlatMap

func FlatMap[T any, R any](s Stream[T], mapper func(T) Stream[R]) Stream[R]

func Map

func Map[T any, R any](s Stream[T], mapper func(T) R) Stream[R]

Map stream 流 类型转换方法

eg:

res := Map(Of(

	TestItem{itemNum: 1, itemValue: "item1"},
	TestItem{itemNum: 2, itemValue: "item2"},
	TestItem{itemNum: 3, itemValue: "item3"},
), func(item TestItem) ToTestItem {
	return ToTestItem{
		itemNum:   item.itemNum,
		itemValue: item.itemValue,
	}
}).ToSlice()
fmt.Println(res)

func Of

func Of[T any](values ...T) Stream[T]

func OfFrom

func OfFrom[T any](generate func(source chan<- T)) Stream[T]

func OfFromParallel

func OfFromParallel[T any](generate func(source chan<- T)) Stream[T]

func OfParallel

func OfParallel[T any](values ...T) Stream[T]

func Range

func Range[T any](source <-chan T, isParallel bool) Stream[T]

func (Stream[T]) AllMatch

func (s Stream[T]) AllMatch(predicate func(T) bool) bool

AllMatch 返回此流中是否全都满足条件

func (Stream[T]) AnyMatch

func (s Stream[T]) AnyMatch(predicate func(T) bool) bool

AnyMatch 返回此流中是否存在元素满足所提供的条件

func (Stream[T]) Collect deprecated

func (s Stream[T]) Collect(collector collectors.Collector[T, T, any]) any

Deprecated: This function is no longer recommended. Please use extracted.Collect() instead.

func (Stream[T]) Concat

func (s Stream[T]) Concat(others ...Stream[T]) Stream[T]

func (Stream[T]) Count

func (s Stream[T]) Count() (count int64)

func (Stream[T]) Distinct

func (s Stream[T]) Distinct(fn func(item T) any) Stream[T]

func (Stream[T]) DropWhile added in v1.1.2

func (s Stream[T]) DropWhile(fn func(item T) bool) Stream[T]

DropWhile 丢弃满足fn 函数(从第一个开始截取),之前的数据

func (Stream[T]) Filter

func (s Stream[T]) Filter(fn func(item T) bool) Stream[T]

func (Stream[T]) FindFirst

func (s Stream[T]) FindFirst() Optional[T]

func (Stream[T]) FindLast

func (s Stream[T]) FindLast() Optional[T]

func (Stream[T]) FlatMap

func (s Stream[T]) FlatMap(mapper func(T) Stream[T]) Stream[T]

func (Stream[T]) FlatMapToFloat32 added in v1.0.4

func (s Stream[T]) FlatMapToFloat32(mapper func(T) Stream[float32]) Stream[float32]

func (Stream[T]) FlatMapToFloat64 added in v1.0.4

func (s Stream[T]) FlatMapToFloat64(mapper func(T) Stream[float64]) Stream[float64]

func (Stream[T]) FlatMapToInt

func (s Stream[T]) FlatMapToInt(mapper func(T) Stream[int]) Stream[int]

func (Stream[T]) FlatMapToInt32 added in v1.0.4

func (s Stream[T]) FlatMapToInt32(mapper func(T) Stream[int32]) Stream[int32]

func (Stream[T]) FlatMapToInt64 added in v1.0.4

func (s Stream[T]) FlatMapToInt64(mapper func(T) Stream[int64]) Stream[int64]

func (Stream[T]) FlatMapToString added in v1.0.3

func (s Stream[T]) FlatMapToString(mapper func(T) Stream[string]) Stream[string]

func (Stream[T]) ForEach

func (s Stream[T]) ForEach(fn func(item T))

func (Stream[T]) GroupingByInt added in v1.0.5

func (s Stream[T]) GroupingByInt(groupFunc func(T) int, opts ...OptFunc[T]) map[int][]T

func (Stream[T]) GroupingByString added in v1.0.5

func (s Stream[T]) GroupingByString(groupFunc func(T) string, opts ...OptFunc[T]) map[string][]T

func (Stream[T]) Joining added in v1.1.3

func (s Stream[T]) Joining(seq string) string

func (Stream[T]) Limit

func (s Stream[T]) Limit(maxSize int64) Stream[T]

func (Stream[T]) Map

func (s Stream[T]) Map(fn func(item T) any) Stream[any]

func (Stream[T]) MapToFloat32 added in v1.0.4

func (s Stream[T]) MapToFloat32(mapper func(T) float32) Stream[float32]

func (Stream[T]) MapToFloat64 added in v1.0.4

func (s Stream[T]) MapToFloat64(mapper func(T) float64) Stream[float64]

func (Stream[T]) MapToInt

func (s Stream[T]) MapToInt(mapper func(T) int) Stream[int]

func (Stream[T]) MapToInt32 added in v1.0.4

func (s Stream[T]) MapToInt32(mapper func(T) int32) Stream[int32]

func (Stream[T]) MapToInt64 added in v1.0.4

func (s Stream[T]) MapToInt64(mapper func(T) int64) Stream[int64]

func (Stream[T]) MapToString added in v1.0.3

func (s Stream[T]) MapToString(mapper func(T) string) Stream[string]

func (Stream[T]) Max

func (s Stream[T]) Max(comparator func(T, T) int) Optional[T]

func (Stream[T]) Min

func (s Stream[T]) Min(comparator func(T, T) int) Optional[T]

func (Stream[T]) NoneMatch

func (s Stream[T]) NoneMatch(predicate func(T) bool) bool

NoneMatch 返回此流中是否全都不满足条件

func (Stream[T]) Peek

func (s Stream[T]) Peek(fn func(item *T)) Stream[T]

func (Stream[T]) PeekP added in v1.1.1

func (s Stream[T]) PeekP(fn func(item T)) Stream[T]

PeekP Point Peek

func (Stream[T]) Reduce

func (s Stream[T]) Reduce(accumulator func(T, T) T) Optional[T]

func (Stream[T]) Reverse

func (s Stream[T]) Reverse() Stream[T]

func (Stream[T]) Skip

func (s Stream[T]) Skip(n int64) Stream[T]

func (Stream[T]) Sorted

func (s Stream[T]) Sorted(less func(a, b T) bool) Stream[T]

func (Stream[T]) SumFloat32Statistics added in v1.1.0

func (s Stream[T]) SumFloat32Statistics() SumFloatStatistics[float32]

func (Stream[T]) SumFloat64Statistics added in v1.0.4

func (s Stream[T]) SumFloat64Statistics() SumFloatStatistics[float64]

func (Stream[T]) SumInt32Statistics added in v1.0.4

func (s Stream[T]) SumInt32Statistics() SumIntStatistics[int32]

func (Stream[T]) SumInt64Statistics added in v1.0.4

func (s Stream[T]) SumInt64Statistics() SumIntStatistics[int64]

func (Stream[T]) SumIntStatistics added in v1.0.4

func (s Stream[T]) SumIntStatistics() SumIntStatistics[int]

func (Stream[T]) TakeWhile added in v1.1.2

func (s Stream[T]) TakeWhile(fn func(item T) bool) Stream[T]

TakeWhile 获取满足fn 函数(从第一个开始(包括)),之前的数据

func (Stream[T]) ToMapInt added in v1.1.0

func (s Stream[T]) ToMapInt(keyMapper func(T) int, valueMapper func(T) T, opts ...func(oldV, newV T) T) map[int]T

func (Stream[T]) ToMapString added in v1.1.0

func (s Stream[T]) ToMapString(keyMapper func(T) string, valueMapper func(T) T, opts ...func(oldV, newV T) T) map[string]T

func (Stream[T]) ToSlice

func (s Stream[T]) ToSlice() []T

func (Stream[T]) Walk

func (s Stream[T]) Walk(fn func(item T, pipe chan<- T)) Stream[T]

Walk 让调用者处理每个Item,调用者可以根据给定的Item编写零个、一个或多个项目

type SumFloatStatistics added in v1.0.4

type SumFloatStatistics[T float32 | float64] struct {
	Count   int64
	Sum     float64
	Max     T
	Min     T
	Average float64
}

func (SumFloatStatistics[T]) GetAverage added in v1.0.4

func (s SumFloatStatistics[T]) GetAverage() float64

func (SumFloatStatistics[T]) GetCount added in v1.0.4

func (s SumFloatStatistics[T]) GetCount() int64

func (SumFloatStatistics[T]) GetMax added in v1.0.4

func (s SumFloatStatistics[T]) GetMax() T

func (SumFloatStatistics[T]) GetMin added in v1.0.4

func (s SumFloatStatistics[T]) GetMin() T

func (SumFloatStatistics[T]) GetSum added in v1.0.4

func (s SumFloatStatistics[T]) GetSum() float64

type SumIntStatistics added in v1.0.4

type SumIntStatistics[T int | int32 | int64] struct {
	Count   int64
	Sum     int64
	Max     T
	Min     T
	Average float64
}

func (SumIntStatistics[T]) GetAverage added in v1.0.4

func (s SumIntStatistics[T]) GetAverage() float64

func (SumIntStatistics[T]) GetCount added in v1.0.4

func (s SumIntStatistics[T]) GetCount() int64

func (SumIntStatistics[T]) GetMax added in v1.0.4

func (s SumIntStatistics[T]) GetMax() T

func (SumIntStatistics[T]) GetMin added in v1.0.4

func (s SumIntStatistics[T]) GetMin() T

func (SumIntStatistics[T]) GetSum added in v1.0.4

func (s SumIntStatistics[T]) GetSum() int64

Jump to

Keyboard shortcuts

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