Documentation ¶
Overview ¶
Package slices provides utilities to work with slices
Index ¶
- func All[T any](arr []T, predicate func(t T) bool) bool
- func Any[T any](arr []T, predicate func(t T) bool) bool
- func Append[T any](arr []T, item T) []T
- func AppendVector[T any](arr, items []T) []T
- func Contains[T any](arr []T, predicate func(t T) bool) bool
- func Cut[T any](arr []T, from, to int) []T
- func Delete[T any](arr []T, idx int) []T
- func DeleteOrder[T any](arr []T, idx int) []T
- func Equals[T any](one, other []T, predicate func(x, y T) bool) (res bool)
- func Extract[T any](arr []T, predicate func(t T) bool) ([]T, T, bool)
- func ExtractIdx[T any](arr []T, idx int) (res []T, item T, ok bool)
- func Filter[T any](arr []T, predicate func(t T) bool) []T
- func FilterInPlace[T any](arr []T, predicate func(t T) bool) []T
- func FilterInPlaceCopy[T any](arr []T, predicate func(t T) bool) []T
- func FilterMap[T, U any](arr []T, predicate func(t T) fp.Option[U]) []U
- func FilterMapTuple[T, U any](arr []T, predicate func(t T) (U, bool)) []U
- func Find[T any](arr []T, predicate func(t T) bool) (res T, ok bool)
- func FindIdx[T any](arr []T, predicate func(t T) bool) (res T, idx int)
- func Fold[T, U any](arr []T, p func(U, T) U, initial U) U
- func FoldSame[T any](arr []T, p func(T, T) T, initial T) T
- func IndexOf[T any](arr []T, predicate func(t T) bool) (pos int)
- func Insert[T any](arr []T, item T, idx int) []T
- func InsertVector[T any](arr, items []T, idx int) (res []T)
- func Map[T, U any](arr []T, predicate func(t T) U) []U
- func MapInPlace[T any](arr []T, predicate func(t T) T) []T
- func Peek[T any](arr []T, idx int) (item T, ok bool)
- func Pop[T any](arr []T) (res []T, item T, ok bool)
- func PopFront[T any](arr []T) (res []T, item T, ok bool)
- func PushFront[T any](arr []T, item T) []T
- func Reduce[T, U any](arr []T, p func(T, T) T) (res T)
- func ReduceSame[T any](arr []T, p func(T, T) T) T
- func Shift[T any](arr []T) ([]T, T, bool)
- func Some[T any](arr []T, predicate func(t T) bool) bool
- func ToMap[V any, K comparable](arr []V, predicate func(x V) K) map[K]V
- func ToMapIdx[V any, K comparable](arr []V, predicate func(x V) K) map[K]WrappedIdx[V]
- func Unshift[T any](arr []T, item T) []T
- type Slice
- func (s *Slice[T]) Append(item T) Slice[T]
- func (s *Slice[T]) AppendVector(items []T) Slice[T]
- func (s Slice[T]) Clone() Slice[T]
- func (s Slice[T]) Contains(fn func(t T) bool) bool
- func (s *Slice[T]) Delete(idx int) Slice[T]
- func (s Slice[T]) Equals(other Slice[T], predicate func(x, y T) bool) (res bool)
- func (s Slice[T]) Filter(predicate func(x T) bool) Slice[T]
- func (s Slice[T]) FilterInPlace(predicate func(x T) bool) Slice[T]
- func (s Slice[T]) FilterInPlaceCopy(predicate func(x T) bool) Slice[T]
- func (s Slice[T]) FilterMap(predicate func(x T) fp.Option[T]) Slice[T]
- func (s Slice[T]) FilterMapTuple(predicate func(x T) (T, bool)) Slice[T]
- func (s Slice[T]) Fold(predicate func(x, y T) T, initial T) T
- func (s Slice[T]) Get(i int) (res T, ok bool)
- func (s Slice[T]) IndexOf(fn func(t T) bool) int
- func (s Slice[T]) Len() int
- func (s Slice[T]) Map(predicate func(T) T) Slice[T]
- func (s Slice[T]) MapInPlace(predicate func(T) T) Slice[T]
- func (s *Slice[T]) Push(item T) Slice[T]
- func (s Slice[T]) Range(fn func(t T, i int) bool)
- func (s Slice[T]) Reduce(predicate func(x, y T) T) T
- func (s Slice[T]) String() string
- type WrappedIdx
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AppendVector ¶ added in v0.3.0
func AppendVector[T any](arr, items []T) []T
func Cut ¶
Cut removes a sector from slice given lower and upper bounds. Bounds are represented as indices of the slice. E.g: Cut([1, 2, 3, 4], 1, 2) -> [1, 4] Cut([4], 0, 0) -> [] Cut will returned the original slice without the cut subslice.
func Delete ¶ added in v0.3.0
Delete removes the element in `idx` position, without preserving array order. In case `idx` is out of bounds, noop.
func DeleteOrder ¶ added in v0.3.0
DeleteOrder removes the element in `idx` position, preserving array order. In case `idx` is out of bounds, noop.
func Extract ¶ added in v0.3.0
Extract gets and deletes the element than matches predicate. Returned values are the modified slice, the item or zero value if not found, and whether item was found
func ExtractIdx ¶ added in v0.3.0
ExtractIdx gets and deletes the element at the given position. Returned values are the modified slice, the item or zero value if not found, and whether item was found
func FilterInPlace ¶
func FilterInPlaceCopy ¶
func FilterMapTuple ¶
func FindIdx ¶ added in v0.3.0
FindIdx returns the first element that matches predicate as well as the position on the slice.
func Insert ¶ added in v0.3.0
Insert places the given item at the position `idx` for the given slice
func InsertVector ¶ added in v0.3.0
InsertVector places the given vector at the position `idx` for the given slice, moving existing elements to the right.
func MapInPlace ¶
func MapInPlace[T any](arr []T, predicate func(t T) T) []T
func Pop ¶ added in v0.3.0
Pop deletes and returns the last item from the slice, starting from the end.
func PushFront ¶ added in v0.3.0
func PushFront[T any](arr []T, item T) []T
PushFront inserts the item at the head of the slice
func ReduceSame ¶
func ReduceSame[T any](arr []T, p func(T, T) T) T
func ToMap ¶
func ToMap[V any, K comparable](arr []V, predicate func(x V) K) map[K]V
func ToMapIdx ¶
func ToMapIdx[V any, K comparable](arr []V, predicate func(x V) K) map[K]WrappedIdx[V]
Types ¶
type Slice ¶
type Slice[T any] []T
func (*Slice[T]) AppendVector ¶ added in v0.3.0
func (Slice[T]) FilterInPlace ¶
func (Slice[T]) FilterInPlaceCopy ¶
func (Slice[T]) FilterMapTuple ¶
func (Slice[T]) MapInPlace ¶
type WrappedIdx ¶
type WrappedIdx[T any] struct { // contains filtered or unexported fields }