slices

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 16, 2022 License: BSD-3-Clause Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func All added in v0.0.2

func All[T any](s []T, p func(v T) bool) bool

func Any added in v0.0.2

func Any[T any](s []T, p func(v T) bool) bool

func Cons

func Cons[T any](v []T, n int) [][]T

Cons returns a slice of slices consisting of successive overlapping n-tuple of elements. All resulting slices have a length of `n`. The result is empty if the input is shorter than `n`.

func Count added in v0.0.2

func Count[T any](s []T, f func(v T) bool) int

Count invokes `f` with each element of `v` and counts the true results.

func CountBy added in v0.0.2

func CountBy[T any, U comparable](s []T, f func(v T) U) map[U]int

CountBy invokes `f` with each element of `v` and counts the number of elements for each value returned by `f`.

func EachCons

func EachCons[T any](v []T, n int, f func(v []T))

EachCons invokes `f` with each element returned by Cons()

func EachSlice

func EachSlice[T any](v []T, n int, f func(v []T))

EachSlice invokes `f` with each element returned by Slice()

func EachSliceBetween

func EachSliceBetween[T any](v []T, slicer func(a, b T) bool, f func(v []T))

EachSliceBetween invokes `f` with each element returned by SliceBetween()

func EachSliceBy

func EachSliceBy[T any, U comparable](v []T, slicer func(a T) U, f func(v []T))

EachSliceBy invokes `f` with each element returned by SliceBy()

func EachZip

func EachZip[T any](v [][]T, f func(v []T))

EachZip invokes `f` with each element returned by Zip(). The arguments must be passed as slice rather than variadic because of the trailing function argument.

func Filter added in v0.0.2

func Filter[T any](v []T, f func(a T) bool) []T

Filter returns a copy of v that includes only the elements for which `f` returns true.

func FilterMap added in v0.0.2

func FilterMap[T any, U any](v []T, f func(a T) (U, bool)) []U

FlatMap invokes `f` with each element of `v` and collects zero or one result per element.

func FilterMapCons added in v0.0.2

func FilterMapCons[T any, U any](v []T, n int, f func(a []T) (U, bool)) []U

FilterMapCons invokes `f` with each `Cons(n)` of `v` and collects zero or one result per invocation.

func FilterMapSlice added in v0.0.2

func FilterMapSlice[T any, U any](v []T, n int, f func(a []T) (U, bool)) []U

FilterMapSlice invokes `f` with each `Slice(n)` of `v` and collects zero or one result per invocation.

func FilterMapSliceBetween added in v0.0.2

func FilterMapSliceBetween[T any, U any](v []T, slicer func(a, b T) bool, f func(a []T) (U, bool)) []U

FilterMapSliceBetween slices `v` according to `slicer`, invokes `f` with each slice and collects zero or one result per invocation.

func FilterMapSliceBy added in v0.0.2

func FilterMapSliceBy[T any, U comparable, V any](v []T, slicer func(a T) U, f func(a []T) (V, bool)) []V

FilterMapSliceBy slices `v` according to `slicer`, invokes `f` with each slice and collects zero or one result per invocation.

func FilterMapZip added in v0.0.2

func FilterMapZip[T any, U comparable](v [][]T, f func(a []T) (U, bool)) []U

FilterMapZip zips the slices of v into one tuple per matching index, invokes `f` with each tuple and collects zero or one result per invocation.

func FlatMap added in v0.0.2

func FlatMap[T any, U any](v []T, f func(a T) []U) []U

FlatMap invokes `f` with each element of `v` and collects zero, one or more results per element.

func FlatMapCons added in v0.0.2

func FlatMapCons[T any, U any](v []T, n int, f func(a []T) []U) []U

FlatMapCons invokes `f` with each `Cons(n)` of `v` and collects zero, one or more results per invocation.

func FlatMapSlice added in v0.0.2

func FlatMapSlice[T any, U any](v []T, n int, f func(a []T) []U) []U

FlatMapSlice invokes `f` with each `Slice(n)` of `v` and collects zero, one or more results per invocation.

func FlatMapSliceBetween added in v0.0.2

func FlatMapSliceBetween[T any, U any](v []T, slicer func(a, b T) bool, f func(a []T) []U) []U

FlatMapSliceBetween slices `v` according to `slicer`, invokes `f` with each slice and collects zero, one or more results per invocation.

func FlatMapSliceBy added in v0.0.2

func FlatMapSliceBy[T any, U comparable, V any](v []T, slicer func(a T) U, f func(a []T) []V) []V

FlatMapSliceBy slices `v` according to `slicer`, invokes `f` with each slice and collects zero, one or more results per invocation.

func FlatMapZip added in v0.0.2

func FlatMapZip[T any, U comparable](v [][]T, f func(a []T) []U) []U

FlatMapZip zips the slices of v into one tuple per matching index, invokes `f` with each tuple and collects zero, one or more results per invocation.

func GroupBy added in v0.0.2

func GroupBy[T any, U comparable](v []T, f func(v T) U) map[U][]T

GroupBy returns a map that groups all the elements of `v` by the value returned by `f`.

func Make

func Make[T any](v ...T) []T

Make is an helper function that creates a slice from individual elements using type inference to determine the type of the resulting slice. All input elements must have matching type.

func Map added in v0.0.2

func Map[T any, U any](v []T, f func(a T) U) []U

Map invokes `f` with each element of `v` and collects one result per element.

func MapCons added in v0.0.2

func MapCons[T any, U any](v []T, n int, f func(a []T) U) []U

MapCons invokes `f` with each `Cons(n)` of `v` and collects one result per invocation.

func MapSlice added in v0.0.2

func MapSlice[T any, U any](v []T, n int, f func(a []T) U) []U

MapSlice invokes `f` with each `Slice(n)` of `v` and collects one result per invocation.

func MapSliceBetween added in v0.0.2

func MapSliceBetween[T any, U any](v []T, slicer func(a, b T) bool, f func(a []T) U) []U

MapSliceBetween slices `v` according to `slicer`, invokes `f` with each slice and collects one result per invocation.

func MapSliceBy added in v0.0.2

func MapSliceBy[T any, U comparable, V any](v []T, slicer func(a T) U, f func(a []T) V) []V

MapSliceBy slices `v` according to `slicer`, invokes `f` with each slice and collects one result per invocation.

func MapZip added in v0.0.2

func MapZip[T any, U comparable](v [][]T, f func(a []T) U) []U

MapZip zips the slices of v into one tuple per matching index, invokes `f` with each tuple and collects one result per invocation.

func Max

func Max[T constraints.Ordered](v []T) T

Max returns the maximum value of `v`. The type of `v` must be a slice with a value type that defines a strict ordered relationship. If `v` is empty, the function return the zero value of the underlying value type.

func MaxBy

func MaxBy[T any, U constraints.Ordered](v []T, f func(a T) U) T

MaxBy returns the first element of `v` for which the result of invoking `f` yields the largest value. If `v` is empty, the zero value of the underlying value type is returned.

func Min

func Min[T constraints.Ordered](v []T) T

Min returns the minimum value of `v`. The type of `v` must be a slice with a value type that defines a strict ordered relationship. If `v` is empty, the function return the zero value of the underlying value type.

func MinBy

func MinBy[T any, U constraints.Ordered](v []T, f func(a T) U) T

MinBy returns the first element of `v` for which the result of invoking `f` yields the smallest value. If `v` is empty, the zero value of the underlying value type is returned.

func MinMax

func MinMax[T constraints.Ordered](v []T) (T, T)

MinMax returns both the minimum abd maximum value of `v`. The type of `v` must be a slice with a value type that defines a strict ordered relationship. If `v` is empty, the function return a pair of zero values for the underlying value type.

func MinMaxBy

func MinMaxBy[T any, U constraints.Ordered](v []T, f func(a T) U) (T, T)

MinMaxBy returns the first elements of `v` for which the result of invoking `f` yields the smallest and the largest values. If `v` is empty, zero values of the underlying value type are returned.

func None added in v0.0.2

func None[T any](s []T, p func(v T) bool) bool

func One added in v0.0.2

func One[T any](s []T, p func(v T) bool) bool

func Reduce added in v0.0.2

func Reduce[T, U any](v []T, memo U, f func(a T, memo U) U) U

Reduce invokes `f` with each element of `v` and the updated memo from the previous invocation.

func Slice

func Slice[T any](v []T, n int) [][]T

Slice returns a slice of slices consisting of successive non-overlapping n-tuple of elements. All resulting slices have a length of `n`, except the last one which may be shorter.

func SliceBetween

func SliceBetween[T any](v []T, slicer func(a, b T) bool) [][]T

SliceBetween invokes the slicer function with each consecutive element (`a`, `b`) and splits the input between `a` and `b` if the slicer returns true. The result is a slice of slices containing all the resulting splits.

func SliceBy

func SliceBy[T any, U comparable](v []T, slicer func(a T) U) [][]T

SliceBy splits the input into contiguous slices for which the function 'slicer' returns the same value.

func Sort

func Sort[T any](v []T, less func(a, b T) bool) []T

Sort returns a sorted copy of `v` according to the comparison function `less`. The original slice is not modified.

func SortBy

func SortBy[T any, U constraints.Ordered](v []T, f func(a T) U) []T

SortBy returns a sorted copy of `v` to the natural sort order of the result of invoking `f` on each element. The original slice is not modified.

func StableSort

func StableSort[T any](v []T, less func(a, b T) bool) []T

StableSort returns a sorted copy of `v` according to the comparison function `less`, preserving the original order of elements that compare equal. The original slice is not modified.

func StableSortBy

func StableSortBy[T any, U constraints.Ordered](v []T, f func(a T) U) []T

StableSortBy returns a sorted copy of `v` according to the natural sort order of the result of invoking `f` on each element, preserving the original order of elements that compare equal. The original slice is not modified.

func Uniq

func Uniq[T comparable](v []T) []T

Uniq returns a copy of `v` where only the first occurrance of a value is preserved. The input must be a slice of comparable values, but does not have to be sorted.

func UniqBy

func UniqBy[T any, U comparable](v []T, f func(a T) U) []T

UniqBy returns a copy of `v` where only the first occurrance of a value is preserved. Values are considered equal if the results of invoking `f` on them are equal. The input does not have to be sorted.

func Zip

func Zip[T any](v ...[]T) [][]T

Zip takes an list of slices and return a slice of slices where each resulting element is a tuple composed of the elements of each input at a given index. The length od the output matches the length of the shortest input.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL