Enumerator

package
v0.0.0-...-731868c Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2026 License: BSD-3-Clause Imports: 3 Imported by: 0

Documentation

Overview

Package Enumerator is a lazy sequence composite in the spirit of Ruby's Enumerator::Lazy. Transforms (Map/Filter/Take) are lazy — they wrap a producer and evaluate nothing until a terminal operation (ToArray/Each/ First/Reduce) pulls items through. This makes it safe to Take a finite prefix of an infinite Generate source.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Interface

type Interface interface {
	// Lazy transforms — return a new Enumerator, evaluate nothing.
	Map(fn func(interface{}) interface{}) Interface
	Filter(pred func(interface{}) bool) Interface
	Take(n int) Interface
	// Terminal operations — force evaluation.
	ToArray() Array.Interface
	Each(fn func(interface{}) Result.Interface) Result.Interface
	First() Result.Interface
	Reduce(seed interface{}, fn func(acc, item interface{}) Result.Interface) Result.Interface
	IsNull() bool
}

Interface is the lazy sequence contract.

func Generate

func Generate(seed interface{}, fn func(interface{}) interface{}) Interface

Generate builds an INFINITE Enumerator: seed, fn(seed), fn(fn(seed)), … It only terminates when a downstream consumer (e.g. Take/First) stops it.

func New

func New(items ...interface{}) Interface

New builds a finite Enumerator over the given items.

func Null

func Null() Interface

Null returns the Null-Object Enumerator.

Jump to

Keyboard shortcuts

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