Documentation
¶
Overview ¶
Package iter is a Go library for working with the golang iter package.
Index ¶
- func Channel[T any](ch <-chan T) iter.Seq[T]
- func Channel2[K, V any](ch <-chan lang.Tuple2[K, V]) iter.Seq2[K, V]
- func Concat[T any](seq ...iter.Seq[T]) iter.Seq[T]
- func Concat2[K, V any](seq ...iter.Seq2[K, V]) iter.Seq2[K, V]
- func Context[T any](ctx context.Context, s iter.Seq[T]) iter.Seq[T]
- func Context2[K, V any](ctx context.Context, s iter.Seq2[K, V]) iter.Seq2[K, V]
- func Deferred[T any](f DeferredF[T]) iter.Seq[T]
- func Deferred2[K, V any](f Deferred2F[K, V]) iter.Seq2[K, V]
- func Empty[T any]() iter.Seq[T]
- func Empty2[K, V any]() iter.Seq2[K, V]
- func Filter[T any](m iter.Seq[T], f func(T) bool) iter.Seq[T]
- func Filter2[K, V any](m iter.Seq2[K, V], f func(K, V) bool) iter.Seq2[K, V]
- func FlatMap[A, B any](s iter.Seq[A], f func(A) iter.Seq[B]) iter.Seq[iter.Seq[B]]
- func FlatMapConcat[A, B any](s iter.Seq[A], f func(A) iter.Seq[B]) iter.Seq[B]
- func Flatten[T any](s iter.Seq[iter.Seq[T]]) iter.Seq[T]
- func ForEach[T any](seq iter.Seq[T], f func(T))
- func GroupBy[T any, K comparable](seq iter.Seq[T], key func(T) K) iter.Seq2[K, iter.Seq[T]]
- func Len[T any](seq iter.Seq[T]) int
- func Len2[K, V any](seq iter.Seq2[K, V]) int
- func Map[A, B any](s iter.Seq[A], f func(A) B) iter.Seq[B]
- func Map2[A, B, A1, B1 any](s iter.Seq2[A, B], f func(A, B) (A1, B1)) iter.Seq2[A1, B1]
- func Range(start, end int) iter.Seq[int]
- func Range2(start, end int) iter.Seq2[int, struct{}]
- func RecoverIf[T any](s iter.Seq[lang.Either[error, T]], p Predicate[error], rec RecoverFunc[T]) iter.Seq[lang.Either[error, T]]
- func RecoverIf2[T any](s iter.Seq2[T, error], p Predicate[error], rec RecoverFunc2[T]) iter.Seq2[T, error]
- func Rows[T any](rows RowLike, scanner Scanner[T]) iter.Seq[lang.Either[error, T]]
- func Rows2[T any](rows RowLike, scanner Scanner[T]) iter.Seq2[T, error]
- func Single[T any](value T) iter.Seq[T]
- func Single2[K, V any](key K, value V) iter.Seq2[K, V]
- func Stream[T any](stream StreamLike[T]) iter.Seq[lang.Either[error, T]]
- func Stream2[T any](stream StreamLike[T]) iter.Seq2[T, error]
- func Throttle[T any](seq iter.Seq[T], d time.Duration) iter.Seq[T]
- func Throttle2[K, V any](seq iter.Seq2[K, V], d time.Duration) iter.Seq2[K, V]
- func ToSeq2[K, V any](it iter.Seq[K]) iter.Seq2[K, V]
- type Deferred2F
- type DeferredF
- type Predicate
- type RecoverFunc
- type RecoverFunc2
- type RowLike
- type Scanner
- type StreamLike
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Channel ¶
Channel returns a sequence that yields values from a channel. If the channel is closed, the sequence is complete.
func Channel2 ¶
Channel2 returns a sequence that yields key/value pairs from a channel. If the channel is closed, the sequence is complete.
func Context ¶
Context returns a new Seq that will yield elements from the input Seq until the context is done.
func Context2 ¶
Context2 returns a new Seq2 that will yield elements from the input Seq2 until the context is done.
func Deferred2 ¶
func Deferred2[K, V any](f Deferred2F[K, V]) iter.Seq2[K, V]
Deferred2 returns a sequence that yields key/value pairs from a function.
func Filter ¶
Filter returns a new iterator that yields only the elements of the input iterator for which the predicate function returns true.
func Filter2 ¶
Filter2 returns a new iterator that yields only the elements of the input iterator for which the predicate function returns true.
func FlatMap ¶
FlatMap returns a new Seq that will yield elements from the input Seq that are the result of applying the function to each element.
func FlatMapConcat ¶
FlatMapConcat returns a new Seq that will yield elements from the input Seq that are the result of applying the function to each element and concatenating the results.
func GroupBy ¶
GroupBy returns a sequence that groups elements from the given sequence by the given key function. The key function is used to determine the group of each element. The resulting sequence yields key-value pairs where the key is the group and the value is a sequence of elements in that group. This function must consume the entire input sequence to group the elements so it's not efficient for large sequences.
func Len ¶
Len returns the number of elements in the sequence. This requires iterating over the entire sequence so it is not efficient for large sequences.
func Len2 ¶
Len2 returns the number of elements in the sequence. This requires iterating over the entire sequence so it is not efficient for large sequences.
func Map ¶
Map applies a function to each element of a sequence and returns a new sequence with the results.
func Map2 ¶
Map2 applies a function to each element of a sequence and returns a new sequence with the results.
func RecoverIf ¶
func RecoverIf[T any](s iter.Seq[lang.Either[error, T]], p Predicate[error], rec RecoverFunc[T]) iter.Seq[lang.Either[error, T]]
RecoverIf applies a function to errors in a sequence and returns a new sequence with the results.
func RecoverIf2 ¶
func RecoverIf2[T any](s iter.Seq2[T, error], p Predicate[error], rec RecoverFunc2[T]) iter.Seq2[T, error]
RecoverIf2 applies a function to errors in a sequence and returns a new sequence with the results.
func Rows ¶
Rows returns a sequence of values from a database RowsLike instance. If an error occurs reading the row it is returned as a Left value in the sequence. If the row is read successfully, the value is returned as a Right value.
func Rows2 ¶
Rows2 returns a sequence of values from a database RowsLike instance. If an error occurs reading the row it is returned as the second yield argument. If the row is read successfully, the value is returned as the first yield argument.
func Stream ¶
Stream converts a StreamLike into an iter.Seq that can be used with the iter package. If the StreamLike returns an error, the iter.Seq will return an either.Left with that error. Otherwise, the iter.Seq will return an either.Right with the value.
func Stream2 ¶
func Stream2[T any](stream StreamLike[T]) iter.Seq2[T, error]
Stream2 converts a StreamLike into an iter.Seq2 that can be used with the iter package. If the StreamLike returns an error, the iter.Seq2 will return that error.
func Throttle ¶
Throttle returns a sequence that yields elements from the given sequence at a maximum rate of one element per duration d.
Types ¶
type Deferred2F ¶
Deferred2F is a function that returns a tuple and a boolean indicating if the sequence is complete.
type DeferredF ¶
DeferredF is a function that returns a value and a boolean indicating if the sequence is complete.
type Predicate ¶
Predicate is a function that returns true if the given value satisfies a condition.
type RecoverFunc ¶
RecoverFunc is a function that returns a sequence of values given an error.
type RecoverFunc2 ¶
RecoverFunc2 is a function that returns a sequence of values given an error.
type RowLike ¶
type RowLike interface { // Next returns true if there are more rows to iterate over. Next() bool // Close closes the sql.Rows. Close() // Err returns the error encountered by the sql.Rows. Err() error // Scan scans the values from the sql.Rows into the given destination. Scan(dest ...any) error }
RowLike is an interface for sql.Rows. It is used to allow for easier testing.
type StreamLike ¶
StreamLike is an interface that matches the gRPC Stream interface for receiving messages. This is existing to avoid dependencies on gRPC yet still be able to implement an Iterator that can be used with gRPC.