Documentation
¶
Index ¶
- func Accumulate[T any](s []T, fn func(T, T) T) []T
- func All[T any](s []T, pred func(T) bool) bool
- func Any[T any](s []T, pred func(T) bool) bool
- func Chain[T any](slices ...[]T) []T
- func Cycle[T any](s []T, count int) []T
- func DropWhile[T any](s []T, pred func(T) bool) []T
- func Filter[T any](s []T, pred func(T) bool) []T
- func Islice[T any](s []T, start, stop, step int) []T
- func Map[T any, U any](s []T, fn func(T) U) []U
- func Max[T Ordered](s []T) (T, error)
- func Min[T Ordered](s []T) (T, error)
- func RangeInts(start, stop, step int) []int
- func Reduce[T any, R any](s []T, init R, fn func(R, T) R) R
- func Repeat[T any](value T, count int) []T
- func Sorted[T Ordered](s []T) []T
- func Sum[T Numeric](s []T) T
- func SumFloat64(s []float64) float64
- func SumInts(s []int) int
- func TakeWhile[T any](s []T, pred func(T) bool) []T
- func Zip[T any](slices ...[]T) [][]T
- type Dict
- func (d *Dict[K, V]) Clear()
- func (d *Dict[K, V]) Contains(key K) bool
- func (d *Dict[K, V]) Copy() *Dict[K, V]
- func (d *Dict[K, V]) Equal(other *Dict[K, V]) bool
- func (d *Dict[K, V]) Get(key K) (V, error)
- func (d *Dict[K, V]) Items() []Pair[K, V]
- func (d *Dict[K, V]) Keys() []K
- func (d *Dict[K, V]) Len() int
- func (d *Dict[K, V]) Pop(key K) (V, error)
- func (d *Dict[K, V]) PopItem() (K, V, error)
- func (d *Dict[K, V]) Remove(key K) error
- func (d *Dict[K, V]) Set(key K, value V)
- func (d *Dict[K, V]) SetDefault(key K, defaultValue V) V
- func (d *Dict[K, V]) Update(other *Dict[K, V])
- func (d *Dict[K, V]) Values() []V
- type EnumeratePair
- type List
- func (l *List[T]) Append(v T)
- func (l *List[T]) AsSlice() []T
- func (l *List[T]) Clear()
- func (l *List[T]) Concat(other any) *List[T]
- func (l *List[T]) Contains(v T) bool
- func (l *List[T]) Copy() *List[T]
- func (l *List[T]) Count(v T) int
- func (l *List[T]) Extend(elems ...T)
- func (l *List[T]) Get(i int) (T, error)
- func (l *List[T]) Index(v T) (int, error)
- func (l *List[T]) Insert(i int, v T) error
- func (l *List[T]) Len() int
- func (l *List[T]) Pop(idxOpt ...int) (T, error)
- func (l *List[T]) Remove(v T) error
- func (l *List[T]) Reverse()
- func (l *List[T]) Set(i int, v T) error
- func (l *List[T]) Slice(start, stop int) *List[T]
- func (l *List[T]) Sort(less func(a, b T) bool) error
- type Numeric
- type Ordered
- type Pair
- type Set
- func (s *Set[T]) Add(v T)
- func (s *Set[T]) AsSlice() []T
- func (s *Set[T]) Clear()
- func (s *Set[T]) Contains(v T) bool
- func (s *Set[T]) Copy() *Set[T]
- func (s *Set[T]) Difference(other *Set[T]) *Set[T]
- func (s *Set[T]) DifferenceWith(other *Set[T]) *Set[T]
- func (s *Set[T]) Discard(v T)
- func (s *Set[T]) Equal(other *Set[T]) bool
- func (s *Set[T]) Intersection(other *Set[T]) *Set[T]
- func (s *Set[T]) IntersectionWith(other *Set[T]) *Set[T]
- func (s *Set[T]) IsDisjoint(other *Set[T]) bool
- func (s *Set[T]) IsSubset(other *Set[T]) bool
- func (s *Set[T]) IsSuperset(other *Set[T]) bool
- func (s *Set[T]) Len() int
- func (s *Set[T]) Pop() (T, error)
- func (s *Set[T]) Remove(v T) error
- func (s *Set[T]) SymmetricDifference(other *Set[T]) *Set[T]
- func (s *Set[T]) SymmetricDifferenceWith(other *Set[T]) *Set[T]
- func (s *Set[T]) Union(other *Set[T]) *Set[T]
- func (s *Set[T]) UnionWith(other *Set[T]) *Set[T]
- func (s *Set[T]) Update(elems ...T)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Accumulate ¶ added in v1.0.2
func Accumulate[T any](s []T, fn func(T, T) T) []T
Accumulate returns running accumulation of elements using fn. For empty input returns nil. The first element of result is s[0].
func Chain ¶ added in v1.0.2
func Chain[T any](slices ...[]T) []T
Chain concatenates multiple slices into one.
func DropWhile ¶ added in v1.0.2
DropWhile drops leading elements satisfying pred and returns the remainder.
func Islice ¶ added in v1.0.2
Islice returns s[start:stop:step] behavior (stop exclusive). Step must not be 0.
func RangeInts ¶ added in v1.0.2
RangeInts returns a slice of ints from start (inclusive) to stop (exclusive) with step.
func Repeat ¶ added in v1.0.2
Repeat returns a slice containing value repeated count times. If count <=0 returns nil.
func Sorted ¶ added in v1.0.2
func Sorted[T Ordered](s []T) []T
Sorted returns a sorted copy of the slice for Ordered types.
func Sum ¶ added in v1.0.2
func Sum[T Numeric](s []T) T
Sum sums a slice of any numeric type and returns the same numeric type.
func SumFloat64 ¶ added in v1.0.2
SumFloat64 sums a slice of float64s.
Types ¶
type Dict ¶
type Dict[K comparable, V any] struct { // contains filtered or unexported fields }
Dict is a Python-like generic dictionary implementation.
func NewDict ¶
func NewDict[K comparable, V any](cap int) *Dict[K, V]
NewDict creates an empty Dict with optional capacity.
func NewDictFromMap ¶
func NewDictFromMap[K comparable, V any](src map[K]V) *Dict[K, V]
NewDictFromMap constructs a Dict by copying entries from provided map.
func (*Dict[K, V]) Keys ¶
func (d *Dict[K, V]) Keys() []K
Keys returns a slice with all keys (iteration order unspecified).
func (*Dict[K, V]) PopItem ¶
PopItem removes and returns an arbitrary key/value pair. Error if empty.
func (*Dict[K, V]) SetDefault ¶
func (d *Dict[K, V]) SetDefault(key K, defaultValue V) V
SetDefault returns the value for key if present; otherwise sets key to defaultValue and returns it.
type EnumeratePair ¶ added in v1.0.2
EnumeratePair is used by Enumerate to return index and value.
func Enumerate ¶ added in v1.0.2
func Enumerate[T any](s []T, start int) []EnumeratePair[T]
Enumerate returns pairs of (index+start, value).
type List ¶
type List[T any] struct { // contains filtered or unexported fields }
List is a Python-like generic list implementation. It wraps a slice and provides common list methods (append, extend, insert, remove, pop, etc.).
func ListFromSlice ¶
ListFromSlice wraps an existing slice (makes a copy) into a List.
func (*List[T]) AsSlice ¶
func (l *List[T]) AsSlice() []T
AsSlice returns a copy of the underlying slice.
func (*List[T]) Get ¶
Get returns element at index i. Supports negative indices. Returns error if out of range.
func (*List[T]) Index ¶
Index returns the index of the first occurrence of v. Returns error if not found.
func (*List[T]) Insert ¶
Insert inserts element at index i (before current element at i). Supports negative indices.
func (*List[T]) Pop ¶
Pop removes and returns element at index i (default last). Supports negative indices.
type Numeric ¶ added in v1.0.2
type Numeric interface {
~int | ~int8 | ~int16 | ~int32 | ~int64 |
~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr |
~float32 | ~float64
}
Numeric matches integer and floating-point numeric types.
type Ordered ¶ added in v1.0.2
type Ordered interface {
~int | ~int8 | ~int16 | ~int32 | ~int64 |
~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr |
~float32 | ~float64 | ~string
}
Ordered is a constraint that matches ordered types for comparisons and sorting.
type Pair ¶
type Pair[K comparable, V any] struct { Key K Value V }
Pair represents a key/value pair returned by Items().
type Set ¶
type Set[T comparable] struct { // contains filtered or unexported fields }
Set is a Python-like generic set implementation. It requires element type T to be comparable. Internally backed by map[T]struct{} for O(1) membership operations.
func NewSet ¶
func NewSet[T comparable](elems ...T) *Set[T]
NewSet creates a new Set with optional initial elements.
func SetFromSlice ¶
func SetFromSlice[T comparable](s []T) *Set[T]
SetFromSlice creates a Set from a slice (duplicates removed).
func (*Set[T]) AsSlice ¶
func (s *Set[T]) AsSlice() []T
AsSlice returns elements as a slice (iteration order is unspecified).
func (*Set[T]) Difference ¶
Difference returns a new set with elements in s that are not in other.
func (*Set[T]) DifferenceWith ¶
DifferenceWith mutates s to remove any elements present in other.
func (*Set[T]) Discard ¶
func (s *Set[T]) Discard(v T)
Discard deletes element if present; no error if missing.
func (*Set[T]) Intersection ¶
Intersection returns a new set with elements common to s and other.
func (*Set[T]) IntersectionWith ¶
IntersectionWith mutates s to keep only elements present in other.
func (*Set[T]) IsDisjoint ¶
IsDisjoint returns true if s has no elements in common with other.
func (*Set[T]) IsSuperset ¶
IsSuperset returns true if s is a superset of other.
func (*Set[T]) SymmetricDifference ¶
SymmetricDifference returns elements in either s or other but not both.
func (*Set[T]) SymmetricDifferenceWith ¶
SymmetricDifferenceWith mutates s to be the symmetric difference between s and other.