Documentation
¶
Overview ¶
Package iterator adds various (record and Lesser) iterators utilities
Index ¶
- Variables
- func NewRecordPipe[T any]() (RecordWriter[*T], RecordIterator[T])
- type RecordIterator
- func CombineIterators[T any](iterators ...RecordIterator[T]) RecordIterator[T]
- func JSONRecordIterator[T any](new func() T, r io.Reader) RecordIterator[T]
- func LogRecordIterator[T any](it RecordIterator[T], pattern string) RecordIterator[T]
- func NewCountIterator[T any](it RecordIterator[T]) (RecordIterator[T], func() int)
- type RecordWriter
Constants ¶
This section is empty.
Variables ¶
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 ¶
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 ¶
RecordWriter writes records. Writing nil will close the pipe