Documentation
¶
Index ¶
- Variables
- func Append[T any](slice []T, v T) []T
- func Concat[T any](s1 []T, s2 []T, others ...[]T) []T
- func Contains[T comparable](s []T, value T) bool
- func Convert[T any, R any](s []T, convert func(v T) R) []R
- func Copy[T any](s []T) []T
- func Find[T comparable](s []T, value T) int
- func FindBy[T any](s []T, predicate func(v T) bool) int
- func FindLast[T comparable](s []T, value T) int
- func First[T any](s []T) option.Option[T]
- func Insert[T any](slice []T, index int, value T) []T
- func Last[T any](s []T) option.Option[T]
- func Max[T constraints.Ordered](s []T) option.Option[T]
- func MaxBy[T any](s []T, less func(v1, v2 T) bool) option.Option[T]
- func Min[T constraints.Ordered](s []T) option.Option[T]
- func MinBy[T any](s []T, less func(v1, v2 T) bool) option.Option[T]
- func Partition[T any](s []T, predicate func(v T) bool) (matched []T, mismatched []T)
- func Prepend[T any](slice []T, v T) []T
- func Reduce[T any, R any](s []T, initial R, reducer func(current R, value T) R) R
- func Remove[T comparable](slice []T, value T) []T
- func RemoveAt[T any](slice []T, index int) []T
- func RemoveBy[T any](slice []T, predicate func(value T) bool) []T
- func Select[T any](s []T, predicate func(v T) bool) []T
- func Sort[T constraints.Ordered](s []T)
- func SortBy[T any](s []T, less func(v1, v2 T) bool)
- func SortStable[T constraints.Ordered](s []T)
- func SortStableBy[T any](s []T, less func(v1, v2 T) bool)
- func Sorted[T constraints.Ordered](s []T) []T
- type Slice
- func (s *Slice[T]) Append(v T)
- func (s *Slice[T]) AppendAll(vs ...T)
- func (s Slice[T]) Copy() []T
- func (s Slice[T]) FindBy(predicate func(v T) bool) int
- func (s Slice[T]) First() option.Option[T]
- func (s *Slice[T]) Insert(index int, value T)
- func (s Slice[T]) IsEmpty() bool
- func (s Slice[T]) Last() option.Option[T]
- func (s Slice[T]) Len() int
- func (s Slice[T]) MaxBy(less func(v1, v2 T) bool) option.Option[T]
- func (s Slice[T]) MinBy(less func(v1, v2 T) bool) option.Option[T]
- func (s Slice[T]) Partition(predicate func(v T) bool) (matched []T, mismatched []T)
- func (s *Slice[T]) Prepend(v T)
- func (s *Slice[T]) PrependAll(vs ...T)
- func (s *Slice[T]) RemoveAt(index int)
- func (s *Slice[T]) RemoveBy(predicate func(value T) bool)
- func (s Slice[T]) Select(predicate func(v T) bool) []T
- func (s Slice[T]) SortBy(less func(v1, v2 T) bool)
- func (s Slice[T]) SortStableBy(less func(v1, v2 T) bool)
- func (s Slice[T]) Sub(begin, end int) Slice[T]
Constants ¶
This section is empty.
Variables ¶
var InvalidIndexErr = errors.New("invalid index")
InvalidIndexErr slice index invalid
Functions ¶
func Concat ¶
func Concat[T any](s1 []T, s2 []T, others ...[]T) []T
Concat concat multi slices into one slice
func Contains ¶
func Contains[T comparable](s []T, value T) bool
Contains return whether slice contains the given value
func Convert ¶
Convert apply convert func on the origin slice, return a new slice contains the generated value.
func Copy ¶
func Copy[T any](s []T) []T
Copy copies a slice. copy can also trim slice underlying array to it's len.
func Find ¶
func Find[T comparable](s []T, value T) int
Find return the index of value; if not found, return -1
func FindLast ¶
func FindLast[T comparable](s []T, value T) int
FindLast return the last index of lvalue; if not found, return -1
func First ¶
First return the first element of slice in a gox.Option, return empty option if slice is empty.
func Insert ¶
Insert inserts new value at the position of slice. The index value must in range [0, len(slice)]
func Last ¶
Last return the last element of slice in a gox.Option, return empty option if slice is empty.
func Max ¶
func Max[T constraints.Ordered](s []T) option.Option[T]
Max returns an Option contains the max value in the slice. If slice is empty, return empty Option.
func MaxBy ¶
MaxBy returns an Option contains the max value in the slice. If slice is empty, return empty Option. The values are compared by less func.
func Min ¶
func Min[T constraints.Ordered](s []T) option.Option[T]
Min returns an Option contains the min value in the slice. If slice is empty, return empty Option.
func MinBy ¶
MinBy returns an Option contains the min value in the slice. If slice is empty, return empty Option. The values are compared by less func.
func Partition ¶
Partition divide slice into two slice, one contains elements match the predicate, the other contains the mismatched.
func Prepend ¶
func Prepend[T any](slice []T, v T) []T
Prepend add a new value to the beginning of slice.
func Remove ¶
func Remove[T comparable](slice []T, value T) []T
Remove removes the value match the given condition predicate.
func RemoveAt ¶
RemoveAt remove the value at the position of slice. The index value must in range [0, len(slice)-1]
func Select ¶
Select apply predicate on the origin slice, return a new slice contains the values match the predicate.
func SortStable ¶
func SortStable[T constraints.Ordered](s []T)
SortStable sorts the slice inplace, with stable sort algorithm
func SortStableBy ¶
SortStableBy sorts the slice inplace, with stable sort algorithm. A less function is specified to compare slice values.
func Sorted ¶
func Sorted[T constraints.Ordered](s []T) []T
Sorted a new slice which contains elements from origin slice, and is sorted.
Types ¶
type Slice ¶ added in v2.3.0
type Slice[T any] []T
Slice type, for adding convinent methods to slice
func New ¶ added in v2.2.0
New create a new new slice, with optinal values If no values are passed, return a nil slice
func (*Slice[T]) Append ¶ added in v2.3.0
func (s *Slice[T]) Append(v T)
Append add a new value to the end of slice, and update the slice.
func (*Slice[T]) AppendAll ¶ added in v2.3.0
func (s *Slice[T]) AppendAll(vs ...T)
AppendAll add values to the end of slice, and update the slice.
func (Slice[T]) Copy ¶ added in v2.3.0
func (s Slice[T]) Copy() []T
Copy copies a slice. copy can also trim slice underlying array to it's len.
func (Slice[T]) FindBy ¶ added in v2.3.0
FindBy find the value match the predicate, return the index; if not found, return -1
func (Slice[T]) First ¶ added in v2.3.0
First return the first element of slice in a gox.Option, return empty option if slice is empty.
func (*Slice[T]) Insert ¶ added in v2.3.0
Insert inserts new value at the position of slice, and update the slice. The index value must in range [0, len(slice)]
func (Slice[T]) Last ¶ added in v2.3.0
Last return the last element of slice in a gox.Option, return empty option if slice is empty.
func (Slice[T]) MaxBy ¶ added in v2.3.0
MaxBy returns an Option contains the max value in the slice. If slice is empty, return empty Option. The values are compared by less func.
func (Slice[T]) MinBy ¶ added in v2.3.0
MinBy returns an Option contains the min value in the slice. If slice is empty, return empty Option. The values are compared by less func.
func (Slice[T]) Partition ¶ added in v2.3.0
Partition divide slice into two slice, one contains elements match the predicate, the other contains the mismatched.
func (*Slice[T]) Prepend ¶ added in v2.3.0
func (s *Slice[T]) Prepend(v T)
Prepend add a new value to the beginning of slice, and update the slice.
func (*Slice[T]) PrependAll ¶ added in v2.3.0
func (s *Slice[T]) PrependAll(vs ...T)
PrependAll new values to the beginning of slice, and update the slice.
func (*Slice[T]) RemoveAt ¶ added in v2.3.0
RemoveAt remove the value at the position of slice, and update the slice . The index value must in range [0, len(slice)-1]
func (*Slice[T]) RemoveBy ¶ added in v2.3.0
RemoveBy remove the value match the given condition predicate, and update the slice inplce.
func (Slice[T]) Select ¶ added in v2.3.0
Select apply predicate on the origin slice, return a new slice contains the values match the predicate.
func (Slice[T]) SortBy ¶ added in v2.3.0
SortBy sorts the slice inplace, a less function is specified to compare slice values.
func (Slice[T]) SortStableBy ¶ added in v2.3.0
SortStableBy sorts the slice inplace, with stable sort algorithm. A less function is specified to compare slice values.