iterator

package
v2.1.6 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2023 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package iterator adds various (record and Lesser) iterators utilities

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrIteratorStop is returned by RecordIterators where there are not more records to be found.
	ErrIteratorStop = errors.New("iterator stop")
)

Functions

func NewRecordPipe

func NewRecordPipe[T any]() (RecordWriter[*T], RecordIterator[T])

NewRecordPipe returns a pipe from writer to Iterator. Band-aid solution for cases where providing an iterator is not feasible and a writer interface is required. Uses channels under the hood

Types

type RecordIterator

type RecordIterator[T any] func() (T, error)

RecordIterator is a function which yield any golang data struct each time called Where there are no more records; ErrIteratorStop should be returned and should not be treated as an error (compare it to io.EOF)

func CombineIterators

func CombineIterators[T any](iterators ...RecordIterator[T]) RecordIterator[T]

CombineIterators will yield the results from each of the consisting iterators the error ErrIteratorStop is expected to progress to the next iterator

func JSONRecordIterator

func JSONRecordIterator[T any](new func() T, r io.Reader) RecordIterator[T]

JSONRecordIterator returns a RecordIterator based on a JSON stream of data, NewLine delimited @new - creator to allocate a new struct for each record; used to allow concurrent use of records yielded @r - byte stream reader containing new line delimited json data

func LogRecordIterator

func LogRecordIterator[T any](it RecordIterator[T], pattern string) RecordIterator[T]

LogRecordIterator prints the contents of the record prior to returning it using the pattern as the fmt-directive where the first argument is the records second is the error as such. log.Printf(pattern, r, err)

func NewCountIterator

func NewCountIterator[T any](it RecordIterator[T]) (RecordIterator[T], func() int)

NewCountIterator returns another iterator which counts the number records

type RecordWriter

type RecordWriter[T any] func(T) error

RecordWriter writes records. Writing nil will close the pipe

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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