riter

package module
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2026 License: MIT Imports: 6 Imported by: 0

README

riter

Rust inspired iterators

Lazy pull style iterators inspired by Rust.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Collect

func Collect[T any](iter Iter[T]) []T

func CollectToMap

func CollectToMap[T any, T1 comparable, T2 any](iter Iter[T], fkv func(T) (T1, T2)) map[T1]T2

Collect elements of an iterator into a map, by function returning (key, value) naming...

func CollectToMapFK

func CollectToMapFK[T any, T1 comparable](iter Iter[T], fk func(T) T1) map[T1]T

Collect elements of an iterator into a map, by function returning key naming...

func Consume

func Consume[T any](iter Iter[T])

consume the elemnts of an iterator to the end, doing nothing with them

func Count

func Count[T any](iter Iter[T]) int

count the elements of an iterator Counting will consume the iterator

func Equal

func Equal[E comparable](iter1, iter2 Iter[E]) bool

compare iterators for equality. Same length and same content. Will consume from iterators not sure how useful this is

func Fold

func Fold[T any, B any](iter Iter[T], init B, f func(B, T) B) B

fold!! (it Iter[T], in B, acc func(B, T) B {} iter[T] is empty, retrurns Zero value for B

func FoldZv

func FoldZv[T any, B any](iter Iter[T], f func(B, T) B) B

FoldZv will use the zero value for the accumulator type as initial value

func ForEach

func ForEach[T any](iter Iter[T], f func(T))

executing f for each element. No return value

func Last

func Last[T any](iter Iter[T]) (T, bool)

func Seq

func Seq[T any](it Iter[T]) iter.Seq[T]

iterator function for go 1.23 style iterators go standard iterators are push style. this funcion converts a pull style iterator to go standard push style iterator that can be used in for loops with range keyword. usage: for val := range riters.Seq(myriter) {}

func SeqIx

func SeqIx[T any](it Iter[T]) iter.Seq2[int, T]

returns a push iterator for underlying pull iterator return int index and the value of type T for the pull iterator usage in for loop: for ix, val := range IterSeqIx(myriter) { ... }

Types

type BufIter

type BufIter[T any] struct {
	// contains filtered or unexported fields
}

buffer iterator - its not a buf its a slice!

func (*BufIter[T]) Next

func (bi *BufIter[T]) Next() (res T, ok bool)

next implementation for buffer iterator

type FieldsIter

type FieldsIter struct {
	// contains filtered or unexported fields
}

the type behind the Fields iterator

func (*FieldsIter) Next

func (fi *FieldsIter) Next() (string, bool)

Next() implementation for Iter

type FieldsIterFn

type FieldsIterFn struct {
	// contains filtered or unexported fields
}

the type behind the Fields iterator

func (*FieldsIterFn) Next

func (fi *FieldsIterFn) Next() (string, bool)

Next() implementation for Iter

type FilterIter

type FilterIter[T any] struct {
	// contains filtered or unexported fields
}

---------------------- Filter ---------------------------------

func (*FilterIter[T]) Next

func (fit *FilterIter[T]) Next() (T, bool)

type FilterMapIter

type FilterMapIter[T, U any] struct {
	// contains filtered or unexported fields
}

---------------------- FilterMap ---------------------------------

func (*FilterMapIter[T, U]) Next

func (fmit *FilterMapIter[T, U]) Next() (U, bool)

type ISplit

type ISplit struct {
	// contains filtered or unexported fields
}

func (*ISplit) Next

func (si *ISplit) Next() (h string, ok bool)

next implementation

type Iter

type Iter[T any] interface {
	Next() (T, bool)
}

func Concat

func Concat[T any](c ...Iter[T]) Iter[T]

func Empty

func Empty[T any]() Iter[T]

Empty -------------------------------------

func Fields

func Fields(s string) Iter[string]

Split a string in fields (words) separated by whitespace, similar to standard strings.Fields, but returns Iter[string]

func FieldsFn

func FieldsFn(s string, fn func(rune) bool) Iter[string]

Split a string in fields (words) separated by code points satisfying fn(rune), similar to standard strings.FieldsFunc, but returns Iter[string]

func FieldsSet

func FieldsSet(s string, cutset string) Iter[string]

Split a string in fields separated by runs of code points contained in string cutset. returns Iter[string]

func Filter

func Filter[T any](it Iter[T], p func(T) bool) Iter[T]

func FilterMap

func FilterMap[T, U any](it Iter[T], mp func(T) (U, bool)) Iter[U]

filterMap is a combination of map and filter the mapping function must return two values u, and ok values where ok is true will be returned in iterator

func Fuse

func Fuse[T any](it Iter[T]) Iter[T]

func Map

func Map[T any, U any](it Iter[T], mf func(T) U) Iter[U]

func NewBufIter

func NewBufIter[T any](buf []T) Iter[T]

create the buffer iterator no underlying types, what difefrence does this make? (like in slices package ?)

func NewBufIterU

func NewBufIterU[S ~[]T, T any](buf S) Iter[T]

create the buffer iterator signature similar to slices.Clone() in std is this signature necessary in order to handle underlying types ??

func NewLineIter

func NewLineIter(r io.Reader) Iter[string]

func Once

func Once[T any](v T) Iter[T]

Once -------------------------------------

func Range

func Range(end int) Iter[int]

func Scan

func Scan[T any, U any](it Iter[T], init U, scanfunc func(U, T) U) Iter[U]

func ScanZv

func ScanZv[T any, U any](it Iter[T], scanfunc func(U, T) U) Iter[U]

ScanZv will use the zero vaue for the accumulator type as initial, so no init value should be provided whether a zero value can be used as initial value is depending on the actual accumulation performed by scanfunc

func Skip

func Skip[T any](i Iter[T], n int) Iter[T]

func SkipUntil

func SkipUntil[T any](it Iter[T], p func(T) bool) Iter[T]

the first name is heavy in use...

func SkipUntilIncl

func SkipUntilIncl[T any](it Iter[T], p func(T) bool) Iter[T]

Lazily skip items until predicate is true. The first item where predicate is true will also be skipped. this is similar to repeat ... until loop as known from Pascal: the body is processed even though predicate turns out to be true one element is skipped even when condition is true in first execution

func SkipUntilInclAlt

func SkipUntilInclAlt[T any](it Iter[T], p func(T) bool) Iter[T]

TST version -----------------------------

func SkipWhile

func SkipWhile[T any](it Iter[T], p func(T) bool) Iter[T]

func Split

func Split(s, sep string) Iter[string]

return Iter[string] for splitting string into substrings separated by a deliminator string

func Split4

func Split4(s, sep string) Iter[string]

func SplitIter2

func SplitIter2(s, sep string) Iter[string]

func SplitIter3

func SplitIter3(s, sep string) Iter[string]

func StringSplit

func StringSplit(s, sep string) Iter[string]

func StringSplit4

func StringSplit4(s, sep string) Iter[string]

func Take

func Take[T any](i Iter[T], n int) Iter[T]

Take the first n elements. iterator as input, iterator as output

func TakeUntil

func TakeUntil[T any](it Iter[T], pred func(T) bool) Iter[T]

func TakeUntilIncl

func TakeUntilIncl[T any](it Iter[T], pred func(T) bool) Iter[T]

This will take elements from the iterator up to, and including, the first element where predicate is true. if all predicates are false. all elemenst will be taken if all predicates are true, the first element will be taken

func TakeWhile

func TakeWhile[T any](it Iter[T], p func(T) bool) Iter[T]

func Variadic

func Variadic[T any](v ...T) Iter[T]

Todo: is that name too nondescript? create buffer iterator from variadic parameters

type MapIter

type MapIter[T, U any] struct {
	// contains filtered or unexported fields
}

---------------------- MAP ---------------------------------

func (*MapIter[T, U]) Next

func (mit *MapIter[T, U]) Next() (U, bool)

type NumIter

type NumIter struct {
	// contains filtered or unexported fields
}

func NewNumIter

func NewNumIter(count int) NumIter

func (*NumIter) NotTake

func (st *NumIter) NotTake() bool

take func could be named NotTake(), would be identical to Skip

func (*NumIter) Skip

func (st *NumIter) Skip() bool

type Pred

type Pred[T any] func(T) bool

type PredIter

type PredIter struct {
	// contains filtered or unexported fields
}

predicate iterator

func NewPredIter

func NewPredIter(pred Pred[int]) PredIter

func (*PredIter) Skip

func (st *PredIter) Skip(e int) bool

func (*PredIter) SkipUntil

func (st *PredIter) SkipUntil(e int) bool

type RangeIter

type RangeIter struct {
	// contains filtered or unexported fields
}

func (*RangeIter) Next

func (t *RangeIter) Next() (int, bool)

TODO: its currently only valid for positive values of step

type SkipIter

type SkipIter[T any] struct {
	// contains filtered or unexported fields
}

func (*SkipIter[T]) Next

func (t *SkipIter[T]) Next() (T, bool)

type SkipUntilIncl3

type SkipUntilIncl3[T any] struct {
	// contains filtered or unexported fields
}

func (*SkipUntilIncl3[T]) Next

func (it *SkipUntilIncl3[T]) Next() (T, bool)

func (*SkipUntilIncl3[T]) Next2

func (suit *SkipUntilIncl3[T]) Next2() (T, bool)

func (*SkipUntilIncl3[T]) Next3

func (suit *SkipUntilIncl3[T]) Next3() (T, bool)

type SkipUntilInclT

type SkipUntilInclT[T any] struct {
	// contains filtered or unexported fields
}

func (*SkipUntilInclT[T]) Next

func (suit *SkipUntilInclT[T]) Next() (T, bool)

type SkipWhileIter

type SkipWhileIter[T any] struct {
	// contains filtered or unexported fields
}

-------------

func (*SkipWhileIter[T]) Next

func (swit *SkipWhileIter[T]) Next() (T, bool)

type SplitIter

type SplitIter struct {
	// contains filtered or unexported fields
}

type for Split iterator

func (*SplitIter) Next

func (si *SplitIter) Next() (string, bool)

next implementation

type TakeIter

type TakeIter[T any] struct {
	// contains filtered or unexported fields
}

func (*TakeIter[T]) Next

func (t *TakeIter[T]) Next() (T, bool)

type TakeWhileIter

type TakeWhileIter[T any] struct {
	// contains filtered or unexported fields
}

-------------

func (*TakeWhileIter[T]) Next

func (twit *TakeWhileIter[T]) Next() (T, bool)

func (*TakeWhileIter[T]) Next2

func (twit *TakeWhileIter[T]) Next2() (T, bool)

Jump to

Keyboard shortcuts

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