Documentation
¶
Index ¶
- func Chain[T any](value T, functions ...func(T) T) T
- func CloneList[T any](source []T) []T
- func CloneMap[K comparable, V any](source map[K]V) map[K]V
- func Compose[T1 any, T2 any, T3 any](f func(T2) T3, g func(T1) T2) func(T1) T3
- func Count[T any](slice []T, predicate func(T) bool) int
- func Curry[T1, T2, R any](fn func(T1, T2) R) func(T1) func(T2) R
- func Distinct[T comparable](slice []T) []T
- func DistinctFunc[T comparable](slice []T, compareFunc func(a, b T) bool) []T
- func Exists[T any](collection []T, condition func(T) bool) bool
- func Filter[T any](source []T, filterFunc func(item T) bool) []T
- func FilterMap[K comparable, V any](source map[K]V, filteringFunc func(key K, value V) bool) map[K]V
- func FlatMap[T1 any](source [][]T1) []T1
- func ForEach[T any](source []T, action func(item T))
- func ForEachWithError[T any](source []T, action func(item T) error) error
- func Map[T1 any, T2 any](source []T1, transform func(item T1) T2) []T2
- func MapFilter[T any](input []T, mapFn func(T) T, filterFn func(T) bool) []T
- func MapFilterMap[K comparable, V any](input map[K]V, mapFn func(K, V) (K, V), filterFn func(K, V) bool) map[K]V
- func MapFilterMapWithError[K comparable, V any](input map[K]V, mapFn func(K, V) (K, V, error), filterFn func(K, V) bool) (map[K]V, error)
- func MapFilterWithError[T any](input []T, mapFn func(T) (T, error), filterFn func(T) bool) ([]T, error)
- func MapReturnWithError[T1 any, T2 any](source []T1, mappingFunc func(item T1) (T2, error)) ([]T2, error)
- func Max[T constraints.Ordered](slice []T) (max T, found bool)
- func MaxBy[T any, R constraints.Ordered](slice []T, getter func(T) R) (max T, found bool)
- func Min[T constraints.Ordered](slice []T) (min T, found bool)
- func MinBy[T any, R constraints.Ordered](slice []T, getter func(T) R) (min T, found bool)
- func Partition[T any](slice []T, predicate func(T) bool) ([]T, []T)
- func Pipe[T1 any, T2 any, T3 any](g func(T1) T2, f func(T2) T3) func(T1) T3
- func Reduce[T any](source []T, reduceFunc func(acc T, item T) T, initialValue T) T
- func Sort[T any](list []T, less func(i, j int) bool) []T
- func Sum[T Summable](list []T) T
- type Summable
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Chain ¶ added in v0.1.7
func Chain[T any](value T, functions ...func(T) T) T
Chain applies a series of functions to a value in sequence. Each function must take a value of type T and return a value of type T.
func CloneList ¶
func CloneList[T any](source []T) []T
CloneList creates a shallow copy of the given list.
func CloneMap ¶
func CloneMap[K comparable, V any](source map[K]V) map[K]V
CloneMap creates a shallow copy of the given map.
func Compose ¶ added in v0.1.7
Compose takes two functions f and g, and returns a new function that applies g first and then f.
func Count ¶ added in v0.1.6
Count function: Counts elements in a slice based on a predicate function
func Curry ¶ added in v0.1.7
func Curry[T1, T2, R any](fn func(T1, T2) R) func(T1) func(T2) R
Curry takes a function fn with two parameters and returns a curried version of it.
func Distinct ¶
func Distinct[T comparable](slice []T) []T
Distinct returns a slice containing only unique elements.
func DistinctFunc ¶
func DistinctFunc[T comparable](slice []T, compareFunc func(a, b T) bool) []T
DistinctFunc returns a slice containing unique elements using a custom comparison function.
func Exists ¶ added in v0.1.5
Exists checks if any element in the collection satisfies the condition. T is a generic type parameter that can represent any type.
func FilterMap ¶
func FilterMap[K comparable, V any](source map[K]V, filteringFunc func(key K, value V) bool) map[K]V
FilterMap filters a hashmap based on a provided function.
func FlatMap ¶
func FlatMap[T1 any](source [][]T1) []T1
FlatMap flattens a list of lists into a single list.
func ForEach ¶
func ForEach[T any](source []T, action func(item T))
ForEach executes a function for each item in the list.
func ForEachWithError ¶
ForEachWithError executes a function for each item and handles errors.
func MapFilter ¶ added in v0.1.8
MapFilter applies a map then filter function to a slice of any type
func MapFilterMap ¶ added in v0.1.8
func MapFilterMap[K comparable, V any](input map[K]V, mapFn func(K, V) (K, V), filterFn func(K, V) bool) map[K]V
MapFilterMap applies a map function and a filter function to a map (hash map).
func MapFilterMapWithError ¶ added in v0.1.8
func MapFilterMapWithError[K comparable, V any](input map[K]V, mapFn func(K, V) (K, V, error), filterFn func(K, V) bool) (map[K]V, error)
MapFilterMapWithError applies a map function that may return an error, then filters the results.
func MapFilterWithError ¶ added in v0.1.8
func MapFilterWithError[T any](input []T, mapFn func(T) (T, error), filterFn func(T) bool) ([]T, error)
MapFilterWithError applies a map function that may return an error, then filters the results.
func MapReturnWithError ¶
func MapReturnWithError[T1 any, T2 any](source []T1, mappingFunc func(item T1) (T2, error)) ([]T2, error)
MapReturnWithError applies a transformation function to each item and handles errors.
func Max ¶ added in v0.1.6
func Max[T constraints.Ordered](slice []T) (max T, found bool)
Generic function to find the highest value
func MaxBy ¶ added in v0.1.6
func MaxBy[T any, R constraints.Ordered](slice []T, getter func(T) R) (max T, found bool)
MaxBy function finds the maximum element based on a getter function
func Min ¶ added in v0.1.6
func Min[T constraints.Ordered](slice []T) (min T, found bool)
Generic function to find the lowest value
func MinBy ¶ added in v0.1.6
func MinBy[T any, R constraints.Ordered](slice []T, getter func(T) R) (min T, found bool)
MinBy function finds the minimum element based on a getter function
func Partition ¶ added in v0.1.6
Partition function splits a slice into two slices based on a predicate function
func Pipe ¶ added in v0.1.7
Pipe takes two functions, g and f, and returns a new function that applies g first and then f.
func Reduce ¶
func Reduce[T any](source []T, reduceFunc func(acc T, item T) T, initialValue T) T
Reduce reduces a list to a single value using the provided function.