Documentation
¶
Index ¶
- func All[V any](s []V, f func(V, int) bool) bool
- func Any[V any](s []V, f func(V, int) bool) bool
- func Filter[V any](s []V, f func(V, int) bool) []V
- func FilterMap[V1, V2 any](s []V1, f func(V1, int) (V2, bool)) []V2
- func FilterMapV[V1, V2 any](s []V1, f func(V1) (V2, bool)) []V2
- func FilterV[V any](s []V, f func(V) bool) []V
- func Head[V any](s []V, n int) []V
- func In[V comparable](s []V, v V) bool
- func Index[V comparable](s []V, v V) int
- func Map[V1, V2 any](s []V1, f func(V1, int) V2) []V2
- func MapV[V1, V2 any](s []V1, f func(V1) V2) []V2
- func Range[T constraints.Real](start, end, step T) []T
- func Reduce[V, T any](s []V, f func(T, V, int) T, initial ...T) T
- func ReduceV[V, T any](s []V, f func(T, V) T, initial ...T) T
- func Slice[V any](s []V, start, end int) []V
- func Sort[V constraints.Ordered](s []V)
- func Tail[V any](s []V, n int) []V
- func ToMap[V1, V2 any, K comparable](s []V1, f func(V1, int) (K, V2)) map[K]V2
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Filter ¶
Filter returns a new slice containing only the elements that pass the given predicate function. If the given slice is nil, nil is returned.
func FilterMap ¶ added in v0.2.0
FilterMap returns a new slice containing the results of applying the given function to each element. If the given slice is nil, nil is returned.
func FilterMapV ¶ added in v0.2.0
FilterMapV is a simplified version of FilterMap. If we don't need the index, we can use FilterMapV instead of FilterMap.
func FilterV ¶ added in v0.2.0
FilterV is a simplified version of Filter. If we don't need the index, we can use FilterV instead of Filter.
func Head ¶ added in v0.2.0
Head returns the first n elements of the given slice. If n is negative, panic. If n is greater than or equal to the length of the slice, the whole slice is returned.
func In ¶
func In[V comparable](s []V, v V) bool
In returns true if the given value is in the given slice.
func Index ¶ added in v0.2.0
func Index[V comparable](s []V, v V) int
Index return the index of the given value in the given slice. If the given value is not in the given slice, -1 is returned.
func Map ¶
Map returns a new slice containing the results of applying the given function to each element. If the given slice is nil, nil is returned.
func MapV ¶ added in v0.2.0
func MapV[V1, V2 any](s []V1, f func(V1) V2) []V2
MapV is a simplified version of Map. If we don't need the index, we can use MapV instead of Map.
func Range ¶ added in v0.2.0
func Range[T constraints.Real](start, end, step T) []T
Range returns a slice of integers from start to end, excluding end. If step is positive, the slice is in increasing order. If step is negative, the slice is in decreasing order. If step is zero, empty slice is returned.
func Reduce ¶ added in v0.2.0
Reduce apply the given function cumulatively to each element of the given slice, from left to right, to reduce the slice to a single value. The initial value, if given, is used as the initial value. If the initial value is not given, the zero value of the type of the result is used. If the given slice is nil, the initial value is returned.
func ReduceV ¶ added in v0.2.0
func ReduceV[V, T any](s []V, f func(T, V) T, initial ...T) T
ReduceV is a simplified version of Reduce. If we don't need the index, we can use ReduceV instead of Reduce.
func Slice ¶ added in v0.2.0
Slice returns a slice of the given slice from start to end, excluding end. Negative index is supported. If start is greater than or equal to end, empty slice is returned.
func Sort ¶ added in v0.1.0
func Sort[V constraints.Ordered](s []V)
Sort sorts the given slice in increasing order.
func Tail ¶ added in v0.2.0
Tail returns the last n elements of the given slice. If n is negative, panic. If n is greater than or equal to the length of the slice, the whole slice is returned.
func ToMap ¶
func ToMap[V1, V2 any, K comparable](s []V1, f func(V1, int) (K, V2)) map[K]V2
ToMap returns a new map containing the results of applying the given function to each element. If the given slice is nil, nil is returned.
Types ¶
This section is empty.