Documentation
¶
Overview ¶
Package seq holds small, pure helpers over iterators and slices: mapping, filtering, flattening, grouping and de-duplicating without the caller holding any mutable state.
The bodies of these helpers hide the accumulation loops so that no caller needs one.
Index ¶
- func Duplicates[T any, K cmp.Ordered](items iter.Seq[T], key func(T) K) []K
- func Filter[T any](items iter.Seq[T], keep func(T) bool) []T
- func FlatMap[T, R any](items iter.Seq[T], f func(T) []R) []R
- func FlatMapIndexed[T, R any](items []T, f func(int, T) []R) []R
- func FlatMapPairs[K, V, R any](pairs iter.Seq2[K, V], f func(K, V) []R) []R
- func FlatMapSlice[T, R any](items []T, f func(T) []R) []R
- func GroupBy[T any, K comparable](items iter.Seq[T], key func(T) K) map[K][]T
- func Map[T, R any](items iter.Seq[T], f func(T) R) []R
- func Occurrences[T any, K comparable](items []T, key func(T) K) map[K][]T
- func Pairs[K comparable, V any](entries map[K]V, keep func(K, V) bool) iter.Seq2[K, V]
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Duplicates ¶
Duplicates returns the keys that occur more than once, sorted.
func FlatMapIndexed ¶
FlatMapIndexed is FlatMap over a slice, passing the index of each item.
func FlatMapPairs ¶
FlatMapPairs is FlatMap over the pairs of an iterator.
func FlatMapSlice ¶
func FlatMapSlice[T, R any](items []T, f func(T) []R) []R
FlatMapSlice is FlatMap over a slice.
func GroupBy ¶
func GroupBy[T any, K comparable](items iter.Seq[T], key func(T) K) map[K][]T
GroupBy returns the items grouped by key, each group in input order.
The items are stably sorted by a textual form of their key and then cut into runs of equal keys, so the grouping needs no mutable state.
func Occurrences ¶
func Occurrences[T any, K comparable](items []T, key func(T) K) map[K][]T
Occurrences returns, for every key, the items that carry it, in input order.
Types ¶
This section is empty.