Documentation
¶
Index ¶
- func At[T any](values []T, at int) T
- func Eq[T comparable](a, b T) bool
- func EqTo[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]) Clip() *Vec[T]
- 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]) SortStable(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 EqTo ¶ added in v0.19.5
func EqTo[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 PipeVec ¶ added in v0.19.7
PipeVec is filter + map from *Vec[T] to *Vec[R].
PipeVec does NOT removes unused capacity, call [Clip] by yourself if needed.
func (*Vec[T]) Append ¶
Append append data to v. see slices.Concat.
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
use cmp.Compare for convenience.
func (*Vec[T]) Clip ¶ added in v0.19.7
Clip removes unused capacity from the (v *Vec[T]), underlying data become data[:len(s):len(s)]. return itself for convenience.
see slices.Clip.
func (*Vec[T]) Contains ¶ added in v0.17.0
Contains reports whether at least one element elem of v satisfies eq(elem, input).
use EqTo for convenience. see github.com/hauntedness/std/hs.EqTo.
func (*Vec[T]) Equal ¶
Equal compare each element, and return true if all the same.
use Eq for convenience. see github.com/hauntedness/std/hs.Eq.
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 EqTo for convenience. see github.com/hauntedness/std/hs.EqTo.
func (*Vec[T]) Sort ¶
Sort sorts the slice x in ascending order as determined by the cmp function. This sort is not guaranteed to be stable.
func (*Vec[T]) SortStable ¶ added in v0.19.6
SortStable sorts the slice x in ascending order as determined by the cmp function.
SortStable keeping the original order of equal elements.