Documentation ¶
Index ¶
- func All[T any](arr []T, predicate func(int, T) bool) bool
- func AllSatisfy[T any, U any](arr1 []T, arr2 []U, predicate func(int, int, T, U) bool) bool
- func Any[T any](arr []T, predicate func(T) bool) bool
- func AnySatisfy[T any, U any](arr1 []T, arr2 []U, predicate func(int, int, T, U) bool) bool
- func Concatenate(elements ...string) string
- func ConcatenateSlice(elements []string) string
- func Count[T comparable](arr []T, element T) int
- func CountIf[T any](arr []T, predicate func(int, T) bool) int
- func Filter[T any](arr []T, predicate func(int, T) bool) []T
- func Find[T comparable](arr []T, element T) int
- func FindIf[T any](arr []T, predicate func(int, T) bool) int
- func Foreach[T any](arr []T, predicate func(int, T) ForeachAction) bool
- func Generate[T any](count int, predicate func(int) T) []T
- func MAll[TK comparable, TV any](m map[TK]TV, predicate func(TK, TV) bool) bool
- func MAllSatisfy[TK comparable, TV any, UK comparable, UV any](m1 map[TK]TV, m2 map[UK]UV, predicate func(TK, UK, TV, UV) bool) bool
- func MAny[TK comparable, TV any](m map[TK]TV, predicate func(TK, TV) bool) bool
- func MAnySatisfy[TK comparable, TV any, UK comparable, UV any](m1 map[TK]TV, m2 map[UK]UV, predicate func(TK, UK, TV, UV) bool) bool
- func MCount[TK comparable, TV comparable](m map[TK]TV, element TV) int
- func MCountIf[TK comparable, TV any](m map[TK]TV, predicate func(TK, TV) bool) int
- func MFilter[TK comparable, TV any](m map[TK]TV, predicate func(TK, TV) bool) map[TK]TV
- func MFindIf[TK comparable, TV any](m map[TK]TV, predicate func(TK, TV) bool) []TK
- func MFindK[TK comparable, TV comparable](m map[TK]TV, element TV) []TK
- func MFindV[TK comparable, TV comparable](m map[TK]TV, element TV) []TK
- func MForeach[TK comparable, TV any](m map[TK]TV, predicate func(TK, TV) ForeachAction) bool
- func MReduce[TK comparable, TV any, U any](m map[TK]TV, init U, predicate func(TK, U, TV) U) U
- func MTransform[TK comparable, TV any, UK comparable, UV any](m map[TK]TV, predicate func(TK, TV) (UK, UV)) map[UK]UV
- func MTransformReduce[TK comparable, TV any, U any](arr map[TK]TV, init U, reduce func(TK, U, U) U, transform func(TK, TV) U) U
- func Max[T constraints.Ordered](x, y T) T
- func Min[T constraints.Ordered](x, y T) T
- func Qsort[T any](arr []T, predicate func(int, int, T, T) int) []T
- func Reduce[T any, U any](arr []T, init U, predicate func(int, U, T) U) U
- func RepeatArray[T any](count int, elements []T) []T
- func RepeatElement[T any](count int, element T) []T
- func Sort[T constraints.Ordered](arr []T) []T
- func Sum[T constraints.Ordered](arr []T, init T) T
- func Transform[T any, U any](arr []T, predicate func(int, T) U) []U
- func TransformReduce[T any, U any](arr []T, init U, reduce func(int, U, U) U, transform func(int, T) U) U
- func Zip[T any, U any](arr1 []T, arr2 []U, predicate func(int, T, U) ForeachAction) bool
- type ForeachAction
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func All ¶
Tests if every element of `arr` matches a predicate that accept index and value as parameters, and returns true, if element match, and false otherwise. The function returns true if every element matches, false otherwise.
func AllSatisfy ¶
Test if all pairs of elements in two slices satisfy a predicate that accept Index-Value pair of two slices, and returns true, if element match, and false otherwise. The function returns true, if all pairs of elements matches, false otherwise.
func Any ¶
Tests if any element of `arr` matches a predicate that accept index and value as parameters, and returns true, if element match, and false otherwise. The function returns true if any element matches, false otherwise.
func AnySatisfy ¶
Test if any pair of elements in two slices satisfy a predicate that accept Index-Value pair of two slices, and returns true, if element match, and false otherwise. The function returns true, if any pair of elements matches, false otherwise.
func Concatenate ¶
Concatenates all arguments into one string.
func ConcatenateSlice ¶
Concatenates strings from the slice into one.
func CountIf ¶
Counts elements in slice that match predicate. The predicate accept Index-Value pair, and returns true, if element need to be counted, false otherwise. The function returns count of counted values.
func Filter ¶
Filters a slice from elements that not match predicate. The predicate accept Index-Value pair, and returns true, if element need to be skipped from resulting slice. The function returns filtered slice.
func Find ¶
func Find[T comparable](arr []T, element T) int
Find element in the slice. Returns -1 if not found, index of element otherwise if found.
func FindIf ¶
Finds element in the slice. Returns first element that matches predicate, that accept Index-Value pair, and returns true, if element was finded, false otherwise. The function returns -1 if none element match predicate.
func Foreach ¶
func Foreach[T any](arr []T, predicate func(int, T) ForeachAction) bool
Calls predicate for each element in the slice. The predicate returns action. Returns true if loop was success (the predicates returned values in the range 0-2), false otherwise.
func MAll ¶
func MAll[TK comparable, TV any](m map[TK]TV, predicate func(TK, TV) bool) bool
Same as `All`, but only for maps, and the predicate accepts Key-Value pair.
func MAllSatisfy ¶
func MAllSatisfy[TK comparable, TV any, UK comparable, UV any, ](m1 map[TK]TV, m2 map[UK]UV, predicate func(TK, UK, TV, UV) bool) bool
Same as `AllSatisfy`, but only for maps, and the predicate accepts two Key-Value pairs of both maps.
func MAny ¶
func MAny[TK comparable, TV any](m map[TK]TV, predicate func(TK, TV) bool) bool
Same as `Any`, but only for maps, and the predicate accepts Key-Value pair.
func MAnySatisfy ¶
func MAnySatisfy[TK comparable, TV any, UK comparable, UV any, ](m1 map[TK]TV, m2 map[UK]UV, predicate func(TK, UK, TV, UV) bool) bool
Same as `AnySatisfy`, but only for maps, and the predicate accepts two Key-Value pairs of both maps.
func MCount ¶
func MCount[TK comparable, TV comparable](m map[TK]TV, element TV) int
Same as `Count`, but only for maps, and the element argument is value of pair to be counted.
func MCountIf ¶
func MCountIf[TK comparable, TV any](m map[TK]TV, predicate func(TK, TV) bool) int
Same as `CountIf`, but only for maps, and the predicate accept Key-Value pair.
func MFilter ¶
func MFilter[TK comparable, TV any](m map[TK]TV, predicate func(TK, TV) bool) map[TK]TV
Same as `Filter`, but only for maps, and the predicate accept Key-Value pair.
func MFindIf ¶
func MFindIf[TK comparable, TV any](m map[TK]TV, predicate func(TK, TV) bool) []TK
Same as `FindIf`, but only for maps, and the predicate accept Key-Value pair. The function returns array of keys, values of that matches the predicate.
func MFindK ¶
func MFindK[TK comparable, TV comparable](m map[TK]TV, element TV) []TK
Same as `Find`, but only for maps, and the predicate accept Key-Value pair.
func MFindV ¶
func MFindV[TK comparable, TV comparable](m map[TK]TV, element TV) []TK
func MForeach ¶
func MForeach[TK comparable, TV any](m map[TK]TV, predicate func(TK, TV) ForeachAction) bool
Same as `Foreach`, but only for maps, and the predicate accept Key-Value pair.
func MReduce ¶
func MReduce[TK comparable, TV any, U any](m map[TK]TV, init U, predicate func(TK, U, TV) U) U
Same as `Reduce`, but only for maps.
func MTransform ¶
func MTransform[TK comparable, TV any, UK comparable, UV any](m map[TK]TV, predicate func(TK, TV) (UK, UV)) map[UK]UV
Same as `Transform`, but only for maps, and the predicate accept Key-Value pair, and returns Key-Value pair, which will stored in map.
func MTransformReduce ¶
func MTransformReduce[TK comparable, TV any, U any](arr map[TK]TV, init U, reduce func(TK, U, U) U, transform func(TK, TV) U) U
Same as `TransformReduce`, but only for maps.
func Qsort ¶
Sorts slice. The function does same as `qsort` in C, but the predicate accepts indexes.
func Reduce ¶
Reduces the slice using the predicate. The predicate accept index, result, and element to be reduced, and returns the result. The function returns result of predicates.
func RepeatArray ¶
Repeats elements in one slice N times.
func RepeatElement ¶
Repeats a one element N times and writes in the slice.
func Sort ¶
func Sort[T constraints.Ordered](arr []T) []T
func Transform ¶
Apply predicate to every element in the slice. The predicate accepts Index-Value pair, and returns changed value with (un-)changed type. The function returns slice of elements with predicate applied.
Types ¶
type ForeachAction ¶
type ForeachAction int
ForEach loop action.
const ( // Do nothing. ForeachNoOp ForeachAction = 0 // Break from loop. ForeachBreak ForeachAction = 1 // Continues loop. ForeachContinue ForeachAction = 2 )