ziter

package
v0.12.1 Latest Latest
Warning

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

Go to latest
Published: Jan 23, 2024 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SliceChunksOfSize added in v0.12.0

func SliceChunksOfSize[T any](items []T, chunkSize int) (chunks [][]T)

Break a slice into multiple slices of the provided size. The last chunk may be smaller than the others.

func SliceIterator added in v0.12.0

func SliceIterator[T any](items []T) *sliceIterator[T]

func SliceNChunks added in v0.12.0

func SliceNChunks[T any](items []T, numChunks int) (chunks [][]T)

Break a slice into N slices of approximately equal size. The last chunk may be smaller than the others.

func WithChunksOfSize added in v0.12.0

func WithChunksOfSize[T any](items []T, chunkSize int, handler ChunkHandler[T]) (err error)

Run the handler on each chunk with a maximum size of chunkSize. The last chunk may be smaller than the others.

func WithNChunks added in v0.12.0

func WithNChunks[T any](items []T, numChunks int, handler ChunkHandler[T]) (err error)

Run the handler N times with chunks of approximately equal size. The last chunk may be smaller than the others.

Types

type ChunkHandler

type ChunkHandler[T any] func(chunk []T) error

type IFilter added in v0.12.0

type IFilter[T any] interface {
	Filter(item T) (keep bool, err error)
}

type ITransform added in v0.12.0

type ITransform[F any, T any] interface {
	Transform(item F) (res T, err error)
}

type Iterator added in v0.9.21

type Iterator[T any] interface {
	Next() (stillOpen bool)
	Err() (err error)
	Item() (item T)
}

func Chunkify added in v0.12.0

func Chunkify[T any](iterator Iterator[T], chunkSize int) Iterator[[]T]

Transforms an iterator of T into an iterator of []T, where each chunk has a max size of chunkSize.

func Filter added in v0.12.0

func Filter[T any](iterator Iterator[T], filter IFilter[T]) Iterator[T]

func Transform added in v0.12.0

func Transform[F any, T any](iterator Iterator[F], transformer ITransform[F, T]) Iterator[T]

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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