iter

package module
v0.0.0-...-a135f18 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2026 License: MIT Imports: 4 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type QuerierContext

type QuerierContext interface {
	QueryContext(ctx context.Context, query string, args ...any) (*sql.Rows, error)
}

QuerierContext describes a type that implements the QueryContext method, such as sql.DB and sql.Tx.

type Scannable

type Scannable[T any] interface {
	Scan(*sql.Rows) error
	*T
}

Scannable represents a type that implements the Scan method consuming a pointer to sql.Rows. This item should declare Scan with a pointer receiver in order for it to be mutated, and in order for it to be instantiated using the data from a sql.Rows scan.

This interface allows direct access to type T as a pointer.

type Seq

type Seq[K any, T any] func(yield func(K, T) bool) bool

Seq defines a sequence iterator function for types K and T.

The Seq will accept a yield function, which will consume the types K and T yielded from the iteration, and should return a true or false on whether the yielded data is OK and the sequence should continue.

Finally, Seq returns a boolean on weather it finished successfully or not.

This involves a two-way communication between Seq and its yield function, allowing eachother to continue once the former is completed, and vice-versa.

Seq should be perceived as an idiomatic Go approach to a "for each" type of iterator.

func QueryContext

func QueryContext[S Scannable[T], T any](
	ctx context.Context, q QuerierContext, query string, values ...any,
) (Seq[*T, error], error)

QueryContext executes a QueryContext call using the input QuerierContext, with input context.Context, query string and values arguments. Type T must be a Scannable[T] type implementing a Scan method that consumes *sql.Rows.

This function returns a sequence iterator that yields a pointer to a type T item and an error if raised. The resulting iterator returns a boolean on weather the iteration was completed successfully or not.

This is a fail-fast implementation and the call will exit on the first raised error (either on item.Scan, or from sql.Rows.Err.

func ReadChunks

func ReadChunks(r io.Reader, size int) Seq[[]byte, error]

Jump to

Keyboard shortcuts

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