collut

package
v0.0.0-...-fba4924 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 20, 2024 License: Apache-2.0 Imports: 1 Imported by: 0

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

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 Identity

func Identity[I any](item I) I

Identity return the identity

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 Ptr

func Ptr[T any](value T) *T

Ptr convert the value to the pointer

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

func SliceContains[T any](slice []T, pred func(elem T) bool) bool

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

func SliceFilter[S any](slice []S, predicate func(item S) bool) (result []S)

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

func SliceFoldl[T any, R any](init R, slice []T, fold func(acc R, next T) R) R

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

func SliceFoldr[T any, R any](init R, list []T, fold func(acc R, next T) R) R

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

func SliceLengthLimit[T any](slice []T, limit int) []T

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

func SliceMap

func SliceMap[S any, R any](slice []S, mapper func(item S) R) []R

SliceMap takes a slice of items and a function and applies the function to each item and takes a result It takes two type parameters. S is the type of the input slice, and R is the type of the result slice. Both of them can be of any type.

func Zero

func Zero[T any]() T

Zero return "zero"/"empty" value for a generic type

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL