list

package
v0.0.0-...-7e023e1 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2024 License: GPL-3.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GeneratorFactory

func GeneratorFactory[T any](fn func(int) T) func(ln int) Generator[T]

func NewIter

func NewIter[T any](l List[T]) liter.Wrapper[T]

func Reduce

func Reduce[T any](l List[T], r Reducer[T]) (t T)

Types

type Generator

type Generator[T any] struct {
	Fn     func(int) T
	Length int
}

Generator fulfills List using a function to generate values by index.

func (Generator[T]) AtIdx

func (g Generator[T]) AtIdx(idx int) T

AtIdx fulfills List returning the value at the specified index.

func (Generator[T]) Len

func (g Generator[T]) Len() int

Len fulfills List returning the length of the list.

func (Generator[T]) Wrap

func (g Generator[T]) Wrap() Wrapper[T]

Wrap the Generator to add Wrapper methods.

type Iter

type Iter[T any] struct {
	List[T]
	I int
}

Iter fulfills liter.Iter by iterating over the list.

func (*Iter[T]) Cur

func (i *Iter[T]) Cur() (t T, done bool)

Cur fulfills liter.Iter returning both the current value and if iteration is done. If iteration is done, T will be the default value.

func (*Iter[T]) Done

func (i *Iter[T]) Done() bool

Done fulfills liter.Iter indicating if iteration is done.

func (*Iter[T]) Idx

func (i *Iter[T]) Idx() int

Idx fulfills liter.Iter and provides the current index.

func (*Iter[T]) Next

func (i *Iter[T]) Next() (t T, done bool)

Next fulfills liter.Iter and increments the index. It returns the current index and a bool indicating if it's done.

func (*Iter[T]) Start

func (i *Iter[T]) Start() (t T, done bool)

Start sets the index to zero. Returns the first element and a bool indicating if it's done.

func (*Iter[T]) Wrapped

func (i *Iter[T]) Wrapped() any

Wrapped fulfills upgrade.Wrapper allowing the underlying List to be upgraded.

type List

type List[T any] interface {
	AtIdx(idx int) T
	Len() int
}

List behaves like an array or slice - it has index values and a length.

type ListSetter

type ListSetter[From, To any] struct {
	List[From]
	Set  func(From, To) To
	Next Setter[To]
}

func Chain

func Chain[From, To any](next *Setter[*To], l List[From], fn func(From, *To)) (out *ListSetter[From, *To])

func InitSetter

func InitSetter[From, To any](l List[From], fn func(From, *To)) *ListSetter[From, *To]

func NewListSetter

func NewListSetter[From, To any](l List[From], fn func(From, To) To) *ListSetter[From, To]

func NewSetter

func NewSetter[From, To any](l List[From], fn func(From, To)) *ListSetter[From, To]

type Reducer

type Reducer[T any] func(T, T) T

type Reverse

type Reverse[T any] struct {
	List[T]
}

Reverse a List

func (Reverse[T]) AtIdx

func (r Reverse[T]) AtIdx(idx int) T

AtIdx returns the value at the index. Fulfills List.

func (Reverse[T]) Slice

func (r Reverse[T]) Slice(buf []T) []T

Slice fulfills Slicer. It converts the underlying Reversed List to a slice.

func (Reverse[T]) Wrap

func (r Reverse[T]) Wrap() Wrapper[T]

Wrap the SliceList to add Wrapper methods.

type Setter

type Setter[T any] interface {
	// contains filtered or unexported methods
}

type SliceList

type SliceList[T any] []T

SliceList wraps a slice to fulfill List.

func (SliceList[T]) AtIdx

func (sl SliceList[T]) AtIdx(idx int) T

AtIdx returns the value at the index.

func (SliceList[T]) Len

func (sl SliceList[T]) Len() int

Len returns the length of the underlying slice.

func (SliceList[T]) Slice

func (sl SliceList[T]) Slice(buf []T) []T

Slice fulfills Slicer and returns the underlying slice.

func (SliceList[T]) Wrap

func (sl SliceList[T]) Wrap() Wrapper[T]

Wrap the SliceList to add Wrapper methods.

type Slicer

type Slicer[T any] interface {
	Slice(buf []T) []T
}

Slicer allows Lists to provide efficient methods for generating slices. If a List fulfills Slicer the ToSlice function will use that to generate a slice instead of iterating over the List.

type Transformer

type Transformer[In, Out any] struct {
	List[In]
	Fn func(In) Out
}

Transformer applies a function to a list to transform it's values.

func (Transformer[In, Out]) AtIdx

func (t Transformer[In, Out]) AtIdx(idx int) Out

AtIdx fulfills List by passing the value at idx in the underlying list into Fn.

func (Transformer[In, Out]) Wrap

func (t Transformer[In, Out]) Wrap() Wrapper[Out]

Wrap the Transformer to add Wrapper methods.

type Wrapper

type Wrapper[T any] struct {
	List[T]
}

Wrapper provides a number of useful methods that can be applied to any List.

func Combinator

func Combinator[T any](setter Setter[T], factory ints.CombinatorFactory[int]) Wrapper[T]

func NewGenerator

func NewGenerator[T any](ln int, fn func(int) T) Wrapper[T]

func NewReverse

func NewReverse[T any](l List[T]) Wrapper[T]

func NewTransformer

func NewTransformer[In, Out any](l List[In], fn func(In) Out) Wrapper[Out]

func Slice

func Slice[T any](s []T) Wrapper[T]

Slice creates a SliceList. Syntact helper that infers type T.

func SliceCombinator

func SliceCombinator[T any](factory ints.CombinatorFactory[int], ls ...List[T]) Wrapper[[]T]

func TransformSlice

func TransformSlice[In, Out any](s []In, fn func(In) Out) Wrapper[Out]

TransformSlice creates a Transformer from a slice. It casts the slice to slice.Slice to fulfill the List interface.

func Wrap

func Wrap[T any](l List[T]) Wrapper[T]

Wrap a List. Also checks that the underlying list is not itself a Wrapper.

func (Wrapper[T]) AssertEqual

func (w Wrapper[T]) AssertEqual(to interface{}, t cmpr.Tolerance) error

func (Wrapper[T]) Iter

func (w Wrapper[T]) Iter() liter.Wrapper[T]

Iter creates an liter.Iter backed by list L.

func (Wrapper[T]) IterFactory

func (w Wrapper[T]) IterFactory() liter.Factory[T]

IterFactory creates an liter.Factory that generates a *list.Iter backed by list L.

func (Wrapper[T]) Reverse

func (w Wrapper[T]) Reverse() Wrapper[T]

Reverse the list.

func (Wrapper[T]) ToSlice

func (w Wrapper[T]) ToSlice(buf []T) []T

ToSlice converts a List to slice. If the underlying List implements Slicer, that will be invoked.

func (Wrapper[T]) Wrapped

func (w Wrapper[T]) Wrapped() any

Wrapped fulfills upgrade.Wrapper.

Jump to

Keyboard shortcuts

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