Documentation
¶
Index ¶
- func Any[S ~[]T, T any](slice S, f func(value T) bool) bool
- func At[S ~[]T, T any](slice S, index int) T
- func AtOptional[S ~[]T, T any](slice S, index int, defaultValue T) T
- func Every[S ~[]T, T any](slice S, f func(value T) bool) bool
- func Fill[S ~[]T, T any](slice S, value T)
- func Filter[S ~[]T, T any](slice S, f func(value T) bool) []T
- func GetOptional[M ~map[K]V, K comparable, V any](m M, key K, defaultValue V) V
- func Keys[M ~map[K]V, K comparable, V any](m M) []K
- func Map[S ~[]T, T any, U any](slice S, f func(value T) U) []U
- func MapInPlace[S ~[]T, T any](slice S, f func(value T) T)
- func MapInPlaceWithIndex[S ~[]T, T any](slice S, f func(value T, index int) T)
- func MapWithIndex[S ~[]T, T any, U any](slice S, f func(value T, index int) U) []U
- func Merge[M ~map[K]V, K comparable, V any](original M, overrides ...M) M
- func MergeInPlace[M ~map[K]V, K comparable, V any](original M, overrides ...M)
- func Reduce[S ~[]T, T any, U any](s S, init U, f func(accumulator U, currentValue T) U) U
- func ReduceRight[S ~[]T, T any, U any](s S, init U, f func(accumulator U, currentValue T) U) U
- func ReduceRightWithIndex[S ~[]T, T any, U any](slice S, init U, f func(accumulator U, currentValue T, currentIndex int) U) U
- func ReduceWithIndex[S ~[]T, T any, U any](s S, init U, f func(accumulator U, currentValue T, currentIndex int) U) U
- func SortedKeys[M ~map[K]V, K cmp.Ordered, V any](m M) []K
- func SortedKeysFunc[M ~map[K]V, K comparable, V any](m M, cmp func(a, b K) int) []K
- func Values[M ~map[K]V, K comparable, V any](m M) []V
- type Entry
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Any ¶
Any test whether at least one element in the slice passes the test implemented by the provided function.
func At ¶
At returns the element at the specified index in the slice. Negative index count back from the last item in the slice.
func AtOptional ¶
AtOptional returns the element at the specified index in the slice or a default value if the index is out of bounds. Negative index count back from the last item in the slice.
func Every ¶
Every test whether all elements in the slice pass the test implemented by the provided function.
func Fill ¶
func Fill[S ~[]T, T any](slice S, value T)
Fill changes all elements in the slice to a static value.
func Filter ¶
Filter creates a new slice with all elements that pass the test implemented by the provided function.
func GetOptional ¶
func GetOptional[M ~map[K]V, K comparable, V any](m M, key K, defaultValue V) V
GetOptional returns the value associated with the key in the map m. If the key is not present, it returns the default value.
func Keys ¶
func Keys[M ~map[K]V, K comparable, V any](m M) []K
Keys returns the keys of the map m. The keys will be in an indeterminate order.
func Map ¶
Map applies a function to each element in the slice and returns a new slice with the results.
func MapInPlace ¶
func MapInPlace[S ~[]T, T any](slice S, f func(value T) T)
MapInPlace applies a function to each element in the slice and modifies the slice in place.
func MapInPlaceWithIndex ¶
MapInPlaceWithIndex applies a function to each element in the slice and modifies the slice in place.
func MapWithIndex ¶
MapWithIndex applies a function to each element in the slice and returns a new slice with the results.
func Merge ¶
func Merge[M ~map[K]V, K comparable, V any](original M, overrides ...M) M
Merge returns a new map that combines the contents of the original and the contents of the given maps.
func MergeInPlace ¶
func MergeInPlace[M ~map[K]V, K comparable, V any](original M, overrides ...M)
MergeInPlace adds the contents of the given maps to the original.
func Reduce ¶
Reduce applies a function against an accumulator and each element in the slice (from left to right) to reduce it to a single value.
func ReduceRight ¶
ReduceRight applies a function against an accumulator and each element in the slice (from right to left) to reduce it to a single value.
func ReduceRightWithIndex ¶
func ReduceRightWithIndex[S ~[]T, T any, U any](slice S, init U, f func(accumulator U, currentValue T, currentIndex int) U) U
ReduceRightWithIndex applies a function against an accumulator and each element in the slice (from right to left) to reduce it to a single value.
func ReduceWithIndex ¶
func ReduceWithIndex[S ~[]T, T any, U any](s S, init U, f func(accumulator U, currentValue T, currentIndex int) U) U
ReduceWithIndex applies a function against an accumulator and each element in the slice (from left to right) to reduce it to a single value.
func SortedKeys ¶
SortedKeys returns the keys of the map m in sorted order.
func SortedKeysFunc ¶
func SortedKeysFunc[M ~map[K]V, K comparable, V any](m M, cmp func(a, b K) int) []K
SortedKeysFunc returns the keys of the map m in sorted order using the given comparison function.
func Values ¶
func Values[M ~map[K]V, K comparable, V any](m M) []V
Values returns the values of the map m. The values will be in an indeterminate order.
Types ¶
type Entry ¶
type Entry[K comparable, V any] struct { Key K Value V }
Entry represents a key-value pair in a map.
func Entries ¶
func Entries[M ~map[K]V, K comparable, V any](m M) []Entry[K, V]
Entries returns the (key, value) pairs of the map m. The pairs will be in an indeterminate order.