Documentation ¶
Index ¶
- func Every[T ~[]E, E comparable](items T, fn Predicate[E]) bool
- func Filter[T ~[]E, E comparable](items T, fn Predicate[E]) T
- func ForEach[T ~[]E, E any](items T, callback func(idx int, item E) bool)
- func GetKeys[K comparable, V any](obj map[K]V) []K
- func GetValues[K comparable, V any](obj map[K]V) []V
- func Map[T any, U any](items []T, mapper func(T) U) []U
- func Reduce[T any, U any](items []T, initial U, reducer func(U, T) U) U
- func Some[T ~[]E, E comparable](items T, fn Predicate[E]) bool
- type Predicate
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Every ¶ added in v0.1.6
func Every[T ~[]E, E comparable](items T, fn Predicate[E]) bool
Return true only if all Predicate(item) == true
func ForEach ¶ added in v0.1.6
Another forms for for loop instead of for .. range, loop will stop when callback with False result
func GetValues ¶
func GetValues[K comparable, V any](obj map[K]V) []V
Retrive all the values from a map
func Map ¶
Iterate over each item in a slice sequentially
Example ¶
nums := []int32{1, 2, 3, 4, 5} ret := Map(nums, func(item int32) int32 { return item * 2 }) fmt.Printf("%v", ret)
Output: {2,4,6,8,10}
func Reduce ¶
Iterate over each item in the slice sequentially, passing the result of the previous iteration to the next iteration's function execution
Example ¶
nums := []int32{1, 2, 3, 4, 5} total := Reduce(nums, 0, func(prev int32, now int32) int32 { return prev + now }) fmt.Printf("%v", total)
Output: 16
func Some ¶ added in v0.1.6
func Some[T ~[]E, E comparable](items T, fn Predicate[E]) bool
Return true if any Predicate(item) == true
Types ¶
type Predicate ¶ added in v0.1.6
type Predicate[T comparable] func(T) bool
Click to show internal directories.
Click to hide internal directories.