Documentation
¶
Overview ¶
Package view provides customisable abstractions over collections. Changes to an underlying collection are reflected in its views, and vice-versa.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Keyer ¶
type Keyer[A comparable, B comparable] struct { To func(A) B From func(B) A }
Keyer defines a mapping between comparable types A and B.
type View ¶
type View[K comparable, V any] interface { Get(K) (V, bool) Set(K, V) Delete(K) Iter() iter.It[iter.Pair[K, V]] }
View is an abstraction over a collection. In the case of a slice, the key is an int.
func FromMap ¶
func FromMap[K comparable, V any, ToK comparable, ToV any]( m map[K]V, filterer func(K, V) bool, keyer Keyer[K, ToK], valuer Valuer[V, ToV], ) View[ToK, ToV]
FromMap returns a View from a Go map collection type.
Filterer defines a function that "hides" the given value from the view when accessed through Get or Iter. It is implemented in terms of the types of the underlying collection, and should not implement the keyer or valuer logic.
Keyer defines a mapping to and from the keys in the underlying collection to the view.
Valuer defines a mapping to and from the values in the underlying collection to the view.
func FromSlice ¶
func FromSlice[V any, ToV any]( s []V, filterer func(int, V) bool, valuer Valuer[V, ToV], ) View[int, ToV]
FromSlice returns a View from a Go list collection type.
Filterer defines a function that "hides" the given value from the view when accessed through Get or Iter. It is implemented in terms of the types of the underlying collection, and should not implement the keyer or valuer logic.
Valuer defines a mapping to and from the values in the underlying collection to the view.