stream

package
v1.1.15 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2025 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Collect

func Collect[E any, R any](s *Stream[E], collector func(iter.Seq[E]) R) R

Collect 通用的收集函数,支持用户自定义逻辑

func GroupBy

func GroupBy[E any, K comparable](s *Stream[E], classifier func(E) K) map[K][]E

GroupBy 根据分类器将元素分组

func ToMap

func ToMap[E any, K comparable, V any](s *Stream[E], mapper func(E) (K, V)) map[K]V

ToMap 将流中的元素转换为 map

Types

type MapEntry

type MapEntry[K comparable, V any] struct {
	Key   K
	Value V
}

type Stream

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

func Concat

func Concat[E any](streams ...*Stream[E]) *Stream[E]

Concat 连接多个流

func FromMap

func FromMap[K comparable, V any](m map[K]V) *Stream[MapEntry[K, V]]

FromMap 从映射创建流

func FromSlice

func FromSlice[E any](slice []E) *Stream[E]

FromSlice 从切片创建流

func Map

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

Map 对流中的每个元素应用映射函数,返回新的流

func NewStream

func NewStream[E any](it iter.Seq[E]) *Stream[E]

NewStream 创建一个新的流

func (*Stream[E]) Distinct

func (s *Stream[E]) Distinct() *Stream[E]

Distinct 去除流中的重复元素

func (*Stream[E]) Filter

func (s *Stream[E]) Filter(predicate func(E) bool) *Stream[E]

Filter 筛选满足条件的元素

func (*Stream[E]) FindFirst

func (s *Stream[E]) FindFirst(predicate func(E) bool) *E

FindFirst 查找第一个满足条件的元素

func (*Stream[E]) Limit

func (s *Stream[E]) Limit(count int) *Stream[E]

Limit 限制流中元素的数量

func (*Stream[E]) Max

func (s *Stream[E]) Max(less func(E, E) bool) *E

Max 返回流中元素的最大值

func (*Stream[E]) Min

func (s *Stream[E]) Min(less func(E, E) bool) *E

Min 返回流中元素的最小值

func (*Stream[E]) Peek

func (s *Stream[E]) Peek(action func(E)) *Stream[E]

Peek 对每个元素执行动作,但不改变流内容

func (*Stream[E]) Skip

func (s *Stream[E]) Skip(n int) *Stream[E]

Skip 跳过流中指定数量的元素

func (*Stream[E]) Sorted

func (s *Stream[E]) Sorted(less func(E, E) bool) *Stream[E]

Sorted 按照比较函数对流中的元素排序

func (*Stream[E]) ToSlice

func (s *Stream[E]) ToSlice() []E

ToSlice 收集元素为切片

Jump to

Keyboard shortcuts

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