Documentation
¶
Index ¶
- Variables
- func Deref[T any](v *T) T
- func Filter[T any](slice []T, f func(v T) bool) []T
- func FilterInPLace[T any](slice []T, f func(v T) bool) []T
- func MapSlice[T any, K any](slice []T, f func(v T) K) []K
- func PointerSlice[T any](slice []T) []*T
- func Ptr[T any](v T) *T
- func PtrIfNotZero[T comparable](v T) *T
- func Reduce[S any, K any](list []S, acc K, f func(acc K, v S) K) K
- func SliceClone[T any](slice []T) []T
- func StringSlice[V, T ~string](s []T) []V
- func Sum[T constraints.Ordered](vals []T) T
- type Map
- type Secret
- type Set
Constants ¶
This section is empty.
Variables ¶
var (
ErrEmptySecret = errors.New("types.Secret: is empty")
)
Functions ¶
func Deref ¶
func Deref[T any](v *T) T
Deref returns derefereced value of v if v is nil then zero value is returned
func Filter ¶
Filter filters the slice using f. The name is inspired from default higher order functions in functional programming.
func FilterInPLace ¶
FilterInPlace The name is inspired from default higher order functions in functional programming.
func MapSlice ¶
MapFunc returns a list constructed by appling a the function f to all items in slice. The name is inspired from default higher order functions in functional programming.
func PointerSlice ¶
func PointerSlice[T any](slice []T) []*T
PointerSlice converts a slice of any type to slice of pointers of the same type
func PtrIfNotZero ¶
func PtrIfNotZero[T comparable](v T) *T
PtrIfNotZero returns pointer to passed value if it is not zero It does not work with slices and maps
func Reduce ¶
Reduce applies the function f to the first two elements of the slice, then applies f to the result of the previous application and the third element, and so on, until all elements have been consumed. The name is inspired from default higher order functions in functional programming.
Eg:
Reduce([]int{1,2,3,4}, 0, func(acc, v int) int {
return acc + v
})
// returns 10
func SliceClone ¶
func SliceClone[T any](slice []T) []T
SliceClone makes a clone of the given slice without changing or sharing the original slice
func StringSlice ¶
func StringSlice[V, T ~string](s []T) []V
StringSlice generates a new slice of type V from the input slice s of type []T. It is useful when converting a slice of one type to another where the types are string or dervied from string
func Sum ¶
func Sum[T constraints.Ordered](vals []T) T
Sum return sum of the values in the given list. It assumes that the type used in slice can hold sum of it, The maximum and minimum values for each type is defined here
Types ¶
type Map ¶
type Map[K constraints.Ordered, V any] map[K]V
type Secret ¶
type Secret struct {
// contains filtered or unexported fields
}
func (*Secret) MarshalJSON ¶
MarshalJSON implements the json.Marshaler interface. The secret value is always marshaled to "******" string.
func (*Secret) Scan ¶
Scan implements the sql.Scanner interface. This function scans a value into a Secret pointer.