Documentation
¶
Overview ¶
Package slice provides utility functions for working with slices in Go.
Index ¶
- func ContainsAny[T comparable](list []T, values ...T) bool
- func DeleteAt[T any](slice []T, index int) (element T, newSlice []T, ok bool)
- func GroupBy[T any, K comparable](list []T, key func(T) K) map[K][]T
- func Intersperse[T any](slice []T, insert T) []T
- func IsSubset[T comparable](a, b []T) bool
- func Last[T any](list []T) (T, bool)
- func Map[E any, F any](seq iter.Seq[E], fn func(e E) F) iter.Seq[F]
- func Pop[T any](slice []T) (element T, newSlice []T, ok bool)
- func Shift[T any](slice []T) (element T, newSlice []T, ok bool)
- func Take[A any](slice []A, n int) []A
- func Uniq[T comparable](list []T) []T
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ContainsAny ¶
func ContainsAny[T comparable](list []T, values ...T) bool
ContainsAny checks if any of the given values present in the list.
func DeleteAt ¶
DeleteAt removes and returns the element at the specified index. It returns the removed element and the modified slice. The third return value (ok) indicates whether an element was removed.
func GroupBy ¶
func GroupBy[T any, K comparable](list []T, key func(T) K) map[K][]T
GroupBy groups a slice of items by a key function.
func Intersperse ¶
func Intersperse[T any](slice []T, insert T) []T
Intersperse puts an item between each element of a slice, returning a new slice.
func IsSubset ¶
func IsSubset[T comparable](a, b []T) bool
IsSubset checks if all elements of slice a are present in slice b.
func Last ¶
Last returns the last element of a slice and true. If the slice is empty, it returns the zero value and false.
func Map ¶
Map takes an iterator of type E and a mapping function, and returns an iterator of type F.
func Pop ¶
Pop removes and returns the last element of a slice. It returns the removed element and the modified slice. The third return value (ok) indicates whether an element was removed.
func Shift ¶
Shift removes and returns the first element of a slice. It returns the removed element and the modified slice. The third return value (ok) indicates whether an element was removed.
func Take ¶
Take returns the first n elements of the given slice. If there are not enough elements in the slice, the whole slice is returned.
func Uniq ¶
func Uniq[T comparable](list []T) []T
Uniq returns a new slice with all duplicates removed.
Types ¶
This section is empty.