Documentation ¶
Overview ¶
Package collut is a package for the collection utils, that contains the helper functions for the standard collections, like slices, maps, ... BE AWARE: If possible use the functions from the "golang.org/x/exp/", like "golang.org/x/exp/slices" use this package only if you are missing some functionality for more information you cna take a look here: https://github.com/golang/go/issues/45955 and also here, for the standard iterator discussion https://github.com/golang/go/discussions/54245
Index ¶
- func FuncCompose[F, S, R any](fst func(F) S, snd func(S) R) func(item F) R
- func Identity[I any](item I) I
- func OpsApplyAll[T any](original T, ops ...func(*T)) T
- func OpsApplyAllRef[T any](item *T, ops ...func(*T))
- func Ptr[T any](value T) *T
- func PtrGetDefault[T any](opt *T, defaultVal T) T
- func PtrNilType[T any]() *T
- func SliceContains[T any](slice []T, pred func(elem T) bool) bool
- func SliceFilter[S any](slice []S, predicate func(item S) bool) (result []S)
- func SliceFoldl[T any, R any](init R, slice []T, fold func(acc R, next T) R) R
- func SliceFoldr[T any, R any](init R, list []T, fold func(acc R, next T) R) R
- func SliceLengthLimit[T any](slice []T, limit int) []T
- func SliceMap[S any, R any](slice []S, mapper func(item S) R) []R
- func Zero[T any]() T
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FuncCompose ¶
func FuncCompose[F, S, R any](fst func(F) S, snd func(S) R) func(item F) R
FuncCompose function composition apply the first function and then apply the second F is an input parameter type for the first function S is an input parameter type for the second func. and result type of the first R is a result type of the second function and the result function in general The composed function will be mapping from the F -> R (type-wise)
func OpsApplyAll ¶
func OpsApplyAll[T any](original T, ops ...func(*T)) T
OpsApplyAll takes an item and returns a new item copy with applied operations BE AWARE: it does not update the original item (it takes it as value, so it is not possible) If you want to modify the original object, use OpsApplyAllRef
func OpsApplyAllRef ¶
func OpsApplyAllRef[T any](item *T, ops ...func(*T))
OpsApplyAllRef apply all operations to the provided item
func PtrGetDefault ¶
func PtrGetDefault[T any](opt *T, defaultVal T) T
PtrGetDefault if the value is nil, return default value
func PtrNilType ¶
func PtrNilType[T any]() *T
PtrNilType converts the type provided to the nil pointer with that associated type
func SliceContains ¶
SliceContains takes a slice and a predicate function that will be called on the elements of the slice, if the predicate function returns true, the slice contains at least one element that matches the predicate T is an element type NOTE: This function is more readable than directly call the IndexFunc
func SliceFilter ¶
SliceFilter takes a slice of items and a predicate to filter the elements S is the type parameter name that represents the type of the input slice
func SliceFoldl ¶
SliceFoldl left fold function for the slice takes an initial value, slice and fold function the fold function takes accumulator as a first parameter and the item from slice as the second T is the type of the elements of the slice, R is a result type
func SliceFoldr ¶
SliceFoldr right fold function for the slice takes an initial value, slice and fold function the fold function takes accumulator as a first parameter and the item from slice as the second T is the type of the elements of the slice, R is a result type
func SliceLengthLimit ¶
SliceLengthLimit limit a length of slice, if the `limit` is greater than the length the slice, the original slice will be returned, otherwise the length will be cut
Types ¶
This section is empty.