Documentation
¶
Index ¶
- func At[T any](values []T, at int) T
- func Eq[T comparable](a, b T) bool
- func EqFunc[T comparable](a T) func(T) bool
- func Loc[T any](values []T, start int, end int) []T
- func Map[T any, R any](values []T, fn func(T) R) []R
- func Pipe[T any, R any](values []T, fn func(T) (R, bool)) []R
- type Vec
- func (v *Vec[T]) Append(data ...T) *Vec[T]
- func (v *Vec[T]) At(index int) T
- func (v *Vec[T]) BinarySearch(target T, cmp func(a, b T) int) (pos int, ok bool)
- func (v *Vec[T]) Clone() *Vec[T]
- func (v *Vec[T]) Contains(fn func(elem T) bool) bool
- func (v *Vec[T]) Data() []T
- func (v *Vec[T]) Equal(other *Vec[T], eq func(a T, b T) bool) bool
- func (v *Vec[T]) Get(index int) T
- func (v *Vec[T]) Index(fn func(elem T) bool) int
- func (v *Vec[T]) IsSorted(cmp func(a T, b T) int) bool
- func (v *Vec[T]) Len() int
- func (v *Vec[T]) Loc(start, end int) *Vec[T]
- func (v *Vec[T]) Pipe(fn func(T) (T, bool)) *Vec[T]
- func (v *Vec[T]) Reduce(initial T, fn func(a, b T) T) T
- func (v *Vec[T]) Reverse() *Vec[T]
- func (v *Vec[T]) Seq() iter.Seq[T]
- func (v *Vec[T]) Set(i int, value T)
- func (v *Vec[T]) Slice(start, end int) *Vec[T]deprecated
- func (v *Vec[T]) Sort(cmp func(a T, b T) int) *Vec[T]
- func (v *Vec[T]) String() string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Eq ¶
func Eq[T comparable](a, b T) bool
func EqFunc ¶ added in v0.18.0
func EqFunc[T comparable](a T) func(T) bool
func Loc ¶
Loc return a slice from values, it accept negative index for start and end.
Loc([1,2,3], 1, -1) --> return [2]
if end is too large, it is equivlent to the len(values).
Types ¶
type Vec ¶
type Vec[T any] struct { // contains filtered or unexported fields }
Vec is simpler slice, mostly you don't need this.
Use *Vec instead of Vec
The zero value is hard to use thus...
func (*Vec[T]) At ¶
At is similar to Get but accept negative index. -1 will locate the last element.
func (*Vec[T]) BinarySearch ¶
BinarySearch searches for target in a sorted slice and returns the earliest position where target is found.
For more detail see: slices.BinarySearch
func (*Vec[T]) Contains ¶ added in v0.17.0
Contains reports whether at least one element elem of v satisfies eq(elem, input). use hs.Eq for convenience.
func (*Vec[T]) Equal ¶
Equal compare each element, and return true if all the same. use hs.Eq for convenience.
func (*Vec[T]) Index ¶ added in v0.17.0
Index IndexFunc returns the first index i satisfying eq(elem, input), or -1 if none do. use hs.Eq for convenience.