iters

package
v0.4.100 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2023 License: ISC Imports: 6 Imported by: 2

Documentation

Overview

SlicePIterator traverses a slice container using pointers to value. thread-safe.

Index

Constants

View Source
const (
	FunctionIteratorCancel int = -1
)

Variables

This section is empty.

Functions

func InitConverterIterator

func InitConverterIterator[K constraints.Ordered, T any](
	iterp *ConverterIterator[K, T],
	keyIterator Iterator[K],
	fn func(key K, isCancel bool) (value T, err error),
)

InitConverterIterator initializes a ConverterIterator struct. ConverterIterator is trhread-safe and re-entrant.

func InitFunctionIterator

func InitFunctionIterator[T any](iterp *FunctionIterator[T], fn func(index int) (value T, err error))

InitFunctionIterator initializes a FunctionIterator struct. functionIterator is thread-safe and re-entrant.

func InitSliceIterator

func InitSliceIterator[T any](iterp *SliceIterator[T], slice []T)

InitSliceIterator initializes a SliceIterator struct. sliceIterator is thread-safe.

func InitSlicePIterator

func InitSlicePIterator[T any](iterp *SliceIterator[T], slice []T)

InitSliceIterator initializes a SliceIterator struct. sliceIterator is thread-safe.

Types

type ConverterIterator

type ConverterIterator[K constraints.Ordered, T any] struct {
	// contains filtered or unexported fields
}

ConverterIterator traverses another iterator and returns converted values. Thread-safe.

func (*ConverterIterator[K, T]) Cancel

func (iter *ConverterIterator[K, T]) Cancel() (err error)

func (*ConverterIterator[K, T]) Next

func (iter *ConverterIterator[K, T]) Next(isSame NextAction) (value T, hasValue bool)

type Delegate

type Delegate[T any] interface {
	// Next finds the next or the same value.
	// isSame indicates what value is sought.
	// value is the sought value or the T type’s zero-value if no value exists.
	// hasValue indicates whether value was assigned a T value.
	Next(isSame NextAction) (value T, hasValue bool)
	// Cancel indicates to the iterator implementation that iteration has concluded
	// and resources should be released.
	Cancel() (err error)
}

Delegate defines the methods that an iterator implementation must implement to use iterator.Delegator

type Delegator

type Delegator[T any] struct {
	Delegate[T]
}

Delegator adds delegating methods that implements the Iterator interface. Delegator is thread-safe if its delegate is thread-safe.

func (*Delegator[T]) Has

func (iter *Delegator[T]) Has() (hasValue bool)

func (*Delegator[T]) HasNext

func (iter *Delegator[T]) HasNext() (ok bool)

func (*Delegator[T]) Next

func (iter *Delegator[T]) Next() (value T, hasValue bool)

func (*Delegator[T]) NextValue

func (iter *Delegator[T]) NextValue() (value T)

func (*Delegator[T]) Same

func (iter *Delegator[T]) Same() (value T, hasValue bool)

func (*Delegator[T]) SameValue

func (iter *Delegator[T]) SameValue() (value T)

type EmptyIterator

type EmptyIterator[T any] struct{}

EmptyIterator is an iterator with no values. thread-safe.

func (*EmptyIterator[T]) Cancel

func (iter *EmptyIterator[T]) Cancel() (err error)

func (*EmptyIterator[T]) Has

func (iter *EmptyIterator[T]) Has() (hasValue bool)

func (*EmptyIterator[T]) HasNext

func (iter *EmptyIterator[T]) HasNext() (ok bool)

func (*EmptyIterator[T]) Next

func (iter *EmptyIterator[T]) Next() (value T, hasValue bool)

func (*EmptyIterator[T]) NextValue

func (iter *EmptyIterator[T]) NextValue() (value T)

func (*EmptyIterator[T]) Same

func (iter *EmptyIterator[T]) Same() (value T, hasValue bool)

func (*EmptyIterator[T]) SameValue

func (iter *EmptyIterator[T]) SameValue() (value T)

type FunctionIterator

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

FunctionIterator traverses a function generatoing values. thread-safe and re-entrant.

func (*FunctionIterator[T]) Cancel

func (iter *FunctionIterator[T]) Cancel() (err error)

func (*FunctionIterator[T]) Next

func (iter *FunctionIterator[T]) Next(isSame NextAction) (value T, hasValue bool)

type Iterator

type Iterator[T any] interface {
	// Next advances to next item and returns it.
	// if the next item does exist, value is valid and hasValue is true.
	// if no next item exists, value is the data type zero-value and hasValue is false.
	Next() (value T, hasValue bool)
	// HasNext advances to next item and returns hasValue true if this next item does exists.
	HasNext() (hasValue bool)
	// NextValue advances to next item and returns it.
	// If no next value exists, the data type zero-value is returned.
	NextValue() (value T)
	// Same returns the same value again.
	// If a value does exist, it is returned in value and hasValue is true.
	// If a value does not exist, the data type zero-value is returned and hasValue is false.
	// If Next, FindNext or HasNext have not been invoked, Same first advances to the first item.
	Same() (value T, hasValue bool)
	// Has returns true if Same() or SameValue will return items.
	// If Next, FindNext or HasNext have not been invoked, Has first advances to the first item.
	Has() (hasValue bool)
	// SameValue returns the same value again.
	// If a value does not exist, the data type zero-value is returned.
	// If Next, FindNext or HasNext have not been invoked, SameValue first advances to the first item.
	SameValue() (value T)
	// Cancel release resources for this iterator.
	// Not every iterator requires a Cancel invocation.
	Cancel() (err error)
}

Iterator allows traversal of values. The iterators in parly.iterator are thread-safe and re-entrant, but generally, this depends on the iterator implementation used.

// triple-expression works for Iterator that do not require Cancel
for iterator := NewIterator(); iterator.HasNext(); {
	v := iterator.SameValue()
}

// conditional expression can be used with all iterators
iterator := NewIterator()
for iterator.HasNext() {
	v := iterator.SameValue()
}
if err = iterator.Cancel(); …

func NewConverterIterator

func NewConverterIterator[K constraints.Ordered, T any](
	keyIterator Iterator[K], fn func(key K, isCancel bool) (value T, err error)) (iterator Iterator[T])

NewConverterIterator returns a converting iterator. ConverterIterator is trhread-safe and re-entrant.

func NewDelegator

func NewDelegator[T any](delegate Delegate[T]) (iter Iterator[T])

NewDelegator returns a parli.Iterator based on a Delegate iterator implementation. Delegator is thread-safe if its delegate is thread-safe.

func NewEmptyIterator

func NewEmptyIterator[T any]() (iterator Iterator[T])

NewEmptyIterator returns an empty iterator of values type T. EmptyIterator is thread-safe.

func NewFunctionIterator

func NewFunctionIterator[T any](
	fn func(index int) (value T, err error),
) (iterator Iterator[T])

NewFunctionIterator returns a parli.Iterator based on a function. functionIterator is thread-safe and re-entrant.

func NewSliceIterator

func NewSliceIterator[T any](slice []T) (iterator Iterator[T])

NewSliceIterator returns an empty iterator of values type T. sliceIterator is thread-safe.

func NewSlicePIterator

func NewSlicePIterator[T any](slice []T) (iterator Iterator[*T])

NewSlicePIterator returns an iterator of pointers to T. SlicePIterator is thread-safe.

type NextAction

type NextAction uint8

NextAction is a unique named type that indicates whether the next or the same value again is sought by Delegate.Next

const (
	IsSame NextAction = 0 // IsSame indicates to Delegate.Next that this is a Same-type incovation
	IsNext NextAction = 1 // IsNext indicates to Delegate.Next that this is a Next-type incovation
)

func (NextAction) String

func (na NextAction) String() (s string)

type SliceIterator

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

SliceIterator traverses a slice container. thread-safe

func (*SliceIterator[T]) Cancel

func (iter *SliceIterator[T]) Cancel() (err error)

func (*SliceIterator[T]) Next

func (iter *SliceIterator[T]) Next(isSame NextAction) (value T, hasValue bool)

type SlicePIterator

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

SlicePIterator traverses a slice container using pointers to value. thread-safe.

func (*SlicePIterator[T]) Cancel

func (iter *SlicePIterator[T]) Cancel() (err error)

func (*SlicePIterator[T]) Next

func (iter *SlicePIterator[T]) Next(isSame NextAction) (value *T, hasValue bool)

Jump to

Keyboard shortcuts

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