Documentation
¶
Index ¶
- Constants
- func Filter[T any](data []T, f func(T) bool) []T
- func FindFunc[T any](data []T, f func(T) bool) (T, bool)
- func FindIFunc[T any](data []T, f func(T) bool) (int, bool)
- func Fold[T, S any](acc T, data []S, f func(T, S) T) T
- func FoldR[T, S any](acc T, data []S, f func(T, S) T) T
- func Intersect[T comparable](a, b []T) []T
- func Map[T, U any](data []T, f func(T) U) []U
- func Unfold[T any](acc T, f func(T) T, p func(T) bool, opts ...UnfoldOption) []T
- func UnfoldI[T any](acc T, f func(T) T, n int, opts ...UnfoldOption) []T
- type UnfoldConfig
- type UnfoldOption
Constants ¶
const ( DefaultMaxIterations = 100000 DefaultStep = 1 )
Variables ¶
This section is empty.
Functions ¶
func Filter ¶
Filter returns a new slice containing only the elements of the slice that satisfy the predicate.
func FindFunc ¶ added in v0.9.3
FindFunc returns the first element in the slice that satisfies the predicate.
It returns the default value for the type and false if no element satisfies the predicate.
func FindIFunc ¶ added in v0.9.3
FindIFunc returns the index of the first element in the slice that satisfies the predicate.
It returns -1 and false if no element satisfies the predicate
func Fold ¶ added in v0.12.0
func Fold[T, S any](acc T, data []S, f func(T, S) T) T
Fold applies a function to each element of the slice. storing the result in an accumulator. It applies the function from left to right.
func FoldR ¶ added in v0.12.0
func FoldR[T, S any](acc T, data []S, f func(T, S) T) T
FoldR applies a function to each element of the slice. storing the result in an accumulator. It applies the function from right to left.
func Intersect ¶
func Intersect[T comparable](a, b []T) []T
Intersect returns the intersection of two comparable slices.
func Map ¶
func Map[T, U any](data []T, f func(T) U) []U
Map applies a function to each element of a slice and returns a new slice with the results.
func Unfold ¶ added in v0.12.0
func Unfold[T any](acc T, f func(T) T, p func(T) bool, opts ...UnfoldOption) []T
Unfold generates a slice by repeatedly applying a function to an accumulator. It includes the accumulator in the result as the first value. If the predicate is always false, it returns nil. It stops when the predicate returns false.
func UnfoldI ¶ added in v0.12.0
func UnfoldI[T any](acc T, f func(T) T, n int, opts ...UnfoldOption) []T
UnfoldI generates a slice by repeatedly applying a function to an accumulator. It includes the accumulator in the result as the first value. The length of the result is equal to i + 1. If i is negative, it returns nil. It stops after i iterations.
Types ¶
type UnfoldConfig ¶ added in v0.12.0
type UnfoldOption ¶ added in v0.12.0
type UnfoldOption func(*UnfoldConfig)
func WithMax ¶ added in v0.12.0
func WithMax(n int) UnfoldOption
WithStep sets the step of the unfold. This does not include the first step. If n is 5, the length of the result is <= 6.
func WithStep ¶ added in v0.12.0
func WithStep(step int) UnfoldOption
WithStep sets the step of the unfold. This does not include the first step. If step is 2, the result will include every second value.