iterator

package
v2.0.4 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2024 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Iter

type Iter[T any] interface {
	// Item returns the current item in the iterator.
	//
	// Next() must be called before calling Item().
	Item() T

	// Next advances the iterator to the next item and returns true if there is
	// an item to consume, and false if the end of the input has been reached,
	// or there has been an error.
	//
	// Next must be called before each call to Item.
	Next() bool

	// Err returns any error produced while iterating.
	Err() error
}

Iter is a simple interface for iterating across a list of items.

This interface is modeled on the bufio.Scanner behavior.

type IterCloser

type IterCloser[T any] interface {
	Iter[T]
	io.Closer
}

IterCloser is an iter, but also embeds the io.Closer interface, so it can be used to wrap a file for iterating through.

func Batch

func Batch[T any](input IterCloser[T], batchSize int) IterCloser[[]T]

func Lines

func Lines(r io.ReadCloser) IterCloser[string]

func Slice

func Slice[T any](slice []T) IterCloser[T]

Jump to

Keyboard shortcuts

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