Documentation
¶
Overview ¶
Package xiter provides iterator utilities for iter.Seq and iter.Seq2.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BoolSeq ¶
BoolSeq is a Seq[bool] with terminal operations And and Or, and the non-terminal Not. Convert any Seq[bool] with BoolSeq(s), or produce one directly from a Seq or Seq2 via MapBool.
type Seq ¶
Seq is a chainable wrapper around iter.Seq. Convert any iter.Seq[V] with Seq[V](s), then chain methods like Limit.
func Transform ¶
Transform yields f(v) for each v in x.
In Go 1.27+ (golang/go#77273), this can become a chainable method:
func (x Seq[V]) Transform[T any](f func(V) T) Seq[T] {
return func(yield func(T) bool) {
x(func(v V) bool { return yield(f(v)) })
}
}
func TransformToSeq ¶
func TransformToSeq[K comparable, V, T any]( x Seq2[K, V], f func(K, V) T, ) Seq[T]
TransformToSeq yields f(k, v) for each (k, v) pair in x.
In Go 1.27+ (golang/go#77273), this can become a chainable method:
func (x Seq2[K, V]) TransformToSeq[T any](f func(K, V) T) Seq[T] {
return func(yield func(T) bool) {
x(func(k K, v V) bool { return yield(f(k, v)) })
}
}
func (Seq[V]) Collect ¶
func (x Seq[V]) Collect() []V
Collect materializes the sequence into a slice.
type Seq2 ¶
type Seq2[K comparable, V any] func(yield func(K, V) bool)
Seq2 is a chainable wrapper around iter.Seq2. K is constrained to comparable to support Collect into a map.
func ToSeq2 ¶
func ToSeq2[K comparable, V any](s iter.Seq2[K, V]) Seq2[K, V]
ToSeq2 converts a standard iter.Seq2[K, V] to Seq2[K, V] for use when type inference is needed.
func Transform2 ¶
func Transform2[K1 comparable, V1 any, K2 comparable, V2 any]( x Seq2[K1, V1], f func(K1, V1) (K2, V2), ) Seq2[K2, V2]
Transform2 yields f(k, v) for each (k, v) pair in x.
In Go 1.27+ (golang/go#77273), this can become a chainable method:
func (x Seq2[K1, V1]) Transform[K2 comparable, V2 any](
f func(K1, V1) (K2, V2),
) Seq2[K2, V2] {
return func(yield func(K2, V2) bool) {
x(func(k K1, v V1) bool { return yield(f(k, v)) })
}
}
func TransformToSeq2 ¶
func TransformToSeq2[V any, K comparable, V2 any]( x Seq[V], f func(V) (K, V2), ) Seq2[K, V2]
TransformToSeq2 yields the (K, V2) pair produced by f for each v in x.
In Go 1.27+ (golang/go#77273), this can become a chainable method:
func (x Seq[V]) TransformToSeq2[K comparable, V2 any](
f func(V) (K, V2),
) Seq2[K, V2] {
return func(yield func(K, V2) bool) {
x(func(v V) bool {
k, v2 := f(v)
return yield(k, v2)
})
}
}
func (Seq2[K, V]) Collect ¶
func (x Seq2[K, V]) Collect() map[K]V
Collect materializes the sequence into a map.
func (Seq2[K, V]) Iter ¶
Iter returns the underlying iter.Seq2[K, V] for interop with stdlib functions.