iterable

package
v0.0.18 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2024 License: MIT Imports: 20 Imported by: 0

Documentation

Overview

Wrapper for iterable objects; heap, list, ring, slice, map, channel, etc. All of them implement 1 or 2 of `Iter() iter.Seq[V]`, `Iter2() iter.Seq[K, V]`, `IntoIter() iter.Seq[V]` or `IntoIter2() iter.Seq2[K, V]`

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Atter added in v0.0.16

type Atter[A hiter.Atter[T], T any] struct {
	hiter.Atter[T]
	Indices hiter.Iterable[int]
}

func (Atter[A, T]) Iter2 added in v0.0.16

func (a Atter[A, T]) Iter2() iter.Seq2[int, T]

type Chan

type Chan[V any] struct {
	Ctx context.Context
	C   <-chan V
}

Chan adds IntoIter method to a receive only channel.

func (Chan[V]) IntoIter

func (c Chan[V]) IntoIter() iter.Seq[V]

type CsvReader added in v0.0.16

type CsvReader struct {
	*csv.Reader
}

CsvReader adds IntoIter2 method to *csv.Reader.

func (CsvReader) IntoIter2 added in v0.0.16

func (dec CsvReader) IntoIter2() iter.Seq2[[]string, error]

type Heap

type Heap[T any] struct {
	heap.Interface
}

Heap adds IntoIter method to a heap.Interface.

func (Heap[T]) IntoIter

func (h Heap[T]) IntoIter() iter.Seq[T]

type JsonDecoder added in v0.0.6

type JsonDecoder struct {
	*json.Decoder
}

JsonDecoder adds IntoIter2 to *json.Decoder.

func (JsonDecoder) IntoIter2 added in v0.0.6

func (dec JsonDecoder) IntoIter2() iter.Seq2[json.Token, error]

type ListAll added in v0.0.5

type ListAll[T any] struct {
	*list.List
}

ListAll adds Iter method to *list.ListAll.

func (ListAll[T]) Iter added in v0.0.5

func (l ListAll[T]) Iter() iter.Seq[T]

func (ListAll[T]) Reverse added in v0.0.14

func (l ListAll[T]) Reverse() ListBackward[T]

type ListBackward

type ListBackward[T any] struct {
	*list.List
}

ListBackward adds Iter method to *list.List. Iter returns an iterator that traverses list backward.

func (ListBackward[T]) Iter

func (l ListBackward[T]) Iter() iter.Seq[T]

func (ListBackward[T]) Reverse added in v0.0.14

func (l ListBackward[T]) Reverse() ListAll[T]

type ListElementAll added in v0.0.5

type ListElementAll[T any] struct {
	*list.Element
}

ListElementAll adds Iter method to *list.Element.

func (ListElementAll[T]) Iter added in v0.0.5

func (l ListElementAll[T]) Iter() iter.Seq[T]

func (ListElementAll[T]) Reverse added in v0.0.14

func (l ListElementAll[T]) Reverse() ListElementBackward[T]

type ListElementBackward added in v0.0.4

type ListElementBackward[T any] struct {
	*list.Element
}

ListElementBackward adds Iter method to *list.Element. Iter returns an iterator that traverses list backward.

func (ListElementBackward[T]) Iter added in v0.0.4

func (l ListElementBackward[T]) Iter() iter.Seq[T]

func (ListElementBackward[T]) Reverse added in v0.0.14

func (l ListElementBackward[T]) Reverse() ListElementAll[T]

type MapAll

type MapAll[K comparable, V any] map[K]V

MapAll adds Iter2 method to map[K]V that merely calling maps.All.

func (MapAll[K, V]) Iter2

func (m MapAll[K, V]) Iter2() iter.Seq2[K, V]

type MapSorted

type MapSorted[K cmp.Ordered, V any] map[K]V

MapSorted adds Iter2 to map[K]V where K is basic ordered type. Iter2 takes snapshot of keys and sort it in ascending order, then returns an iterator over pairs of the keys and values that correspond to each key.

func (MapSorted[K, V]) Iter2

func (m MapSorted[K, V]) Iter2() iter.Seq2[K, V]

func (MapSorted[K, V]) Reverse added in v0.0.14

func (m MapSorted[K, V]) Reverse() MapSortedFunc[map[K]V, K, V]

type MapSortedFunc

type MapSortedFunc[M ~map[K]V, K comparable, V any] struct {
	M   M
	Cmp func(K, K) int
	// contains filtered or unexported fields
}

MapSortedFunc adds Iter2 to map[K]V. Iter2 takes snapshot of keys and sort it using the comparison function, then returns an iterator over pairs of the keys and values that correspond to each key.

func (MapSortedFunc[M, K, V]) Iter2

func (m MapSortedFunc[M, K, V]) Iter2() iter.Seq2[K, V]

func (MapSortedFunc[M, K, V]) Reverse added in v0.0.14

func (m MapSortedFunc[M, K, V]) Reverse() MapSortedFunc[M, K, V]

type Nexter added in v0.0.14

type Nexter[
	T any,
	Nexter interface {
		Next() bool
		Err() error
	},
] struct {
	Nexter  Nexter
	Scanner func(Nexter) (T, error)
}

SqlRows adds IntoIter2 to *sql.Rows. For detailed behavior, see databaseiter.SqlRows.

func (Nexter[T, N]) IntoIter2 added in v0.0.14

func (n Nexter[T, N]) IntoIter2() iter.Seq2[T, error]

type Peekable added in v0.0.14

type Peekable[V any] struct {
	// contains filtered or unexported fields
}

Peekable adds the read-ahead ability to iter.Seq[V].

The zero value of Peekable is not valid. Allocate one by NewPeekable.

func NewPeekable added in v0.0.14

func NewPeekable[V any](seq iter.Seq[V]) *Peekable[V]

NewPeekable initializes a peekable iterator. The caller must call *Peekable.Stop to release resources regardless of usage.

func (*Peekable[V]) IntoIter added in v0.0.14

func (p *Peekable[V]) IntoIter() iter.Seq[V]

IntoIter returns p as an iterator form.

func (*Peekable[V]) Peek added in v0.0.14

func (p *Peekable[V]) Peek(n int) []V

Peek reads the next n elements without advancing the iterator. Peeked elements are only removed through the iterator returned from IntoIter.

func (*Peekable[V]) Stop added in v0.0.14

func (p *Peekable[V]) Stop()

Stop releases resources allocated by NewPeekable.

type Peekable2 added in v0.0.14

type Peekable2[K, V any] struct {
	// contains filtered or unexported fields
}

Peekable2 adds the read-ahead ability to iter.Seq2[K, V].

The zero value of Peekable2 is not valid. Allocate one by NewPeekable2.

func NewPeekable2 added in v0.0.14

func NewPeekable2[K, V any](seq iter.Seq2[K, V]) *Peekable2[K, V]

NewPeekable2 initializes a peekable iterator. The caller must call *Peekable2.Stop to release resources regardless of usage.

func (*Peekable2[K, V]) IntoIter2 added in v0.0.14

func (p *Peekable2[K, V]) IntoIter2() iter.Seq2[K, V]

IntoIter2 returns p as an iterator form.

func (*Peekable2[K, V]) Peek added in v0.0.14

func (p *Peekable2[K, V]) Peek(n int) []hiter.KeyValue[K, V]

Peek reads the next n key-value pairs without advancing the iterator. Peeked pairs are only removed through the iterator returned from IntoIter.

func (*Peekable2[K, V]) Stop added in v0.0.14

func (p *Peekable2[K, V]) Stop()

Stop releases resources allocated by NewPeekable2.

type Range

type Range[T hiter.Numeric] struct {
	Start, End                 T
	ExcludesStart, IncludesEnd bool
}

Range adds Iter method to the pair of 2 Numeric values.

func (Range[T]) Iter

func (r Range[T]) Iter() iter.Seq[T]

Iter returns an iterator that yields sequential Numeric values. Values start from `start` and steps toward `end`. At each step value is increased by 1 if start < end, otherwise decreased by 1. By default, values are in the half open interval [Start, End).

func (Range[T]) Reverse added in v0.0.14

func (r Range[T]) Reverse() Range[T]

type Repeatable

type Repeatable[V any] struct {
	V V
	N int
}

Repeatable generates an iterator that generates V N times.

func (Repeatable[V]) Iter

func (r Repeatable[V]) Iter() iter.Seq[V]

type Repeatable2

type Repeatable2[K, V any] struct {
	K K
	V V
	N int
}

Repeatable2 generates an iterator that generates pairs of K and V N times.

func (Repeatable2[K, V]) Iter2

func (r Repeatable2[K, V]) Iter2() iter.Seq2[K, V]

type RepeatableFunc added in v0.0.3

type RepeatableFunc[V any] struct {
	FnV func() V
	N   int
}

RepeatableFunc generates an iterator that generates value returned from FnV N times.

func (RepeatableFunc[V]) Iter added in v0.0.3

func (r RepeatableFunc[V]) Iter() iter.Seq[V]

type RepeatableFunc2 added in v0.0.3

type RepeatableFunc2[K, V any] struct {
	FnK func() K
	FnV func() V
	N   int
}

RepeatableFunc2 generates an iterator that generates pairs of value that FnK and FnV return N times.

func (RepeatableFunc2[K, V]) Iter2 added in v0.0.3

func (r RepeatableFunc2[K, V]) Iter2() iter.Seq2[K, V]

type Resumable added in v0.0.13

type Resumable[V any] struct {
	// contains filtered or unexported fields
}

Resumable converts the input iter.Seq[V] into stateful form by calling iter.Pull.

The zero value of Resumable is not valid. Allocate one by NewResumable.

func NewResumable added in v0.0.13

func NewResumable[V any](seq iter.Seq[V]) *Resumable[V]

NewResumable wraps seq into stateful form so that the iterator can be break-ed and resumed. The caller must call *Resumable.Stop to release resources regardless of usage.

func (*Resumable[V]) IntoIter added in v0.0.13

func (r *Resumable[V]) IntoIter() iter.Seq[V]

IntoIter returns an iterator over the input iterator. The iterator can be paused by break and later resumed without replaying data.

func (*Resumable[V]) Stop added in v0.0.13

func (r *Resumable[V]) Stop()

Stop releases resources allocated by NewResumable.

type Resumable2 added in v0.0.13

type Resumable2[K, V any] struct {
	// contains filtered or unexported fields
}

Resumable2 converts the input iter.Seq2[K, V] into stateful form by calling iter.Pull2.

The zero value of Resumable2 is not valid. Allocate one by NewResumable2.

func NewResumable2 added in v0.0.13

func NewResumable2[K, V any](seq iter.Seq2[K, V]) *Resumable2[K, V]

NewResumable2 wraps seq into stateful form so that the iterator can be break-ed and resumed. The caller must call *Resumable2.Stop to release resources regardless of usage.

func (*Resumable2[K, V]) IntoIter2 added in v0.0.13

func (r *Resumable2[K, V]) IntoIter2() iter.Seq2[K, V]

IntoIter2 returns an iterator over the input iterator. The iterator can be paused by break and later resumed without replaying data.

func (*Resumable2[K, V]) Stop added in v0.0.13

func (r *Resumable2[K, V]) Stop()

Stop releases resources allocated by NewResumable2.

type RingAll added in v0.0.9

type RingAll[T any] struct {
	*ring.Ring
}

RingAll adds Iter method to *ring.RingAll.

func (RingAll[T]) Iter added in v0.0.9

func (r RingAll[T]) Iter() iter.Seq[T]

func (RingAll[T]) Reverse added in v0.0.14

func (r RingAll[T]) Reverse() RingBackward[T]

type RingBackward

type RingBackward[T any] struct {
	*ring.Ring
}

RingBackward adds Iter method to *ring.Ring. Iter returns an iterator that traverses ring backward.

func (RingBackward[T]) Iter

func (r RingBackward[T]) Iter() iter.Seq[T]

func (RingBackward[T]) Reverse added in v0.0.14

func (r RingBackward[T]) Reverse() RingAll[T]

type Scanner

type Scanner struct {
	*bufio.Scanner
}

func (Scanner) IntoIter added in v0.0.9

func (s Scanner) IntoIter() iter.Seq[string]

type SliceAll

type SliceAll[E any] []E

SliceAll adds Iter and Iter2 methods to slice of any element E. They merely call slices.Values, slices.All respectively.

func (SliceAll[E]) Iter

func (s SliceAll[E]) Iter() iter.Seq[E]

func (SliceAll[E]) Iter2

func (s SliceAll[E]) Iter2() iter.Seq2[int, E]

func (SliceAll[E]) Reverse added in v0.0.14

func (s SliceAll[E]) Reverse() SliceBackward[E]

type SliceBackward

type SliceBackward[E any] []E

SliceBackward adds Iter and Iter2 methods to slice of any element E. They return iterators over []E traversing them backward with descending indices.

func (SliceBackward[E]) Iter

func (s SliceBackward[E]) Iter() iter.Seq[E]

func (SliceBackward[E]) Iter2

func (s SliceBackward[E]) Iter2() iter.Seq2[int, E]

func (SliceBackward[E]) Reverse added in v0.0.14

func (s SliceBackward[E]) Reverse() SliceAll[E]

type SqlRows added in v0.0.9

type SqlRows[T any] struct {
	Rows    *sql.Rows
	Scanner func(*sql.Rows) (T, error)
}

SqlRows adds IntoIter2 to *sql.Rows. For detailed behavior, see databaseiter.SqlRows.

func (SqlRows[T]) IntoIter2 added in v0.0.9

func (s SqlRows[T]) IntoIter2() iter.Seq2[T, error]

type SyncMap

type SyncMap[K comparable, V any] struct {
	*sync.Map
}

SyncMap adds Iter2 method that merely calls sync.Map.Range.

func (SyncMap[K, V]) Iter2

func (s SyncMap[K, V]) Iter2() iter.Seq2[K, V]

type XmlDecoder added in v0.0.6

type XmlDecoder struct {
	*xml.Decoder
}

XmlDecoder adds IntoIter2 to *xml.Decoder.

func (XmlDecoder) IntoIter2 added in v0.0.6

func (dec XmlDecoder) IntoIter2() iter.Seq2[xml.Token, error]

Jump to

Keyboard shortcuts

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