collector

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Jan 3, 2024 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Collect

func Collect[E any, C any](seq iter.Seq[E], collector Collector[E, C]) C

Collect collects all elements in iter.Seq to collector.

Types

type Collector

type Collector[E any, C any] interface {
	CollectSeq(seq iter.Seq[E])
	Collect(x E)
	Finish() C
}

Collector collect all elements in iter.Seq to dest type.

func Distinct

func Distinct[E comparable]() Collector[E, iter.Seq[E]]

Distinct remove duplicated elements in iter.Seq and returns a new iter.Seq which elements yield in visit order.

func DistinctFunc

func DistinctFunc[E any](f func(E, E) int) Collector[E, iter.Seq[E]]

DistinctFunc remove duplicated elements in iter.Seq and returns a new iter.Seq which elements yield in visit order.

func GroupBy

func GroupBy[E any, K comparable](f func(E) K) Collector[E, iter.Seq[tuple.Pair[K, iter.Seq[E]]]]

GroupBy collects all elements in iter.Seq and group by key using given function.

func Partition

func Partition[E any](f func(E) bool) Collector[E, tuple.Pair[iter.Seq[E], iter.Seq[E]]]

Partition creates two iter.Seq, split by the given predicate function.

The first iter.Seq contains elements that satisfies the predicate. The second iter.Seq

func ToMap

func ToMap[E any, K comparable, V any](f func(E) (K, V)) Collector[E, map[K]V]

ToMap collects all elements in iter.Seq to map.

func ToOrderedMap

func ToOrderedMap[E any, K cmp.Ordered, V any](f func(E) (K, V)) Collector[E, *ordered.Map[K, V]]

func ToOrderedMapFunc

func ToOrderedMapFunc[E, K, V any](cmp func(K, K) int, f func(E) (K, V)) Collector[E, *ordered.Map[K, V]]

ToOrderedMapFunc collects all elements in iter.Seq to ordered map.

func ToOrderedSet

func ToOrderedSet[E any, V cmp.Ordered](f func(E) V) Collector[E, *ordered.Set[V]]

func ToOrderedSetFunc

func ToOrderedSetFunc[E, V any](cmp func(V, V) int, f func(E) V) Collector[E, *ordered.Set[V]]

ToOrderedSetFunc collects all elements in iter.Seq to ordered set.

func ToSlice

func ToSlice[E any]() Collector[E, []E]

ToSlice collects all elements in iter.Seq to slice.

Jump to

Keyboard shortcuts

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