types

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2025 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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

func Filter[T any](slice []T, f func(v T) bool) []T

Filter filters the slice using f. The name is inspired from default higher order functions in functional programming.

func FilterInPLace

func FilterInPLace[T any](slice []T, f func(v T) bool) []T

FilterInPlace The name is inspired from default higher order functions in functional programming.

func MapSlice

func MapSlice[T any, K any](slice []T, f func(v T) K) []K

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 Ptr

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

ToPtr returns pointer to passed value

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

func Reduce[S any, K any](list []S, acc K, f func(acc K, v S) K) K

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

func (Map[K, _]) Keys

func (m Map[K, _]) Keys() []K

Keys returns keys of the map

func (Map[K, V]) Scan

func (m Map[K, V]) Scan(src interface{}) error

Scan implements the Scanner interface for Map. It scans the value into m.

func (Map[K, V]) Value

func (m Map[K, V]) Value() (driver.Value, error)

Value returns m as a json string value

func (Map[_, V]) Values

func (m Map[_, V]) Values() []V

Values returns values from the map

type Secret

type Secret struct {
	// contains filtered or unexported fields
}

func NewSecret

func NewSecret(value string) (*Secret, error)

func (*Secret) MarshalJSON

func (p *Secret) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface. The secret value is always marshaled to "******" string.

func (*Secret) Scan

func (p *Secret) Scan(src interface{}) error

Scan implements the sql.Scanner interface. This function scans a value into a Secret pointer.

func (*Secret) Secret

func (p *Secret) Secret() string

Secret returns the secret value as plain text.

func (*Secret) Set

func (p *Secret) Set(value string) error

func (Secret) String

func (p Secret) String() string

String implements the fmt.Stringer interface The secret value is always returned as "******" string.

func (Secret) Value

func (p Secret) Value() (driver.Value, error)

type Set

type Set[T constraints.Ordered] map[T]bool

func (*Set[T]) Add

func (ss *Set[T]) Add(s T) *Set[T]

Add adds a value

func (*Set[T]) Remove

func (ss *Set[T]) Remove(s T) *Set[T]

Remove removes a value

func (Set[T]) Slice

func (ss Set[T]) Slice() []T

Slice returns slice of strings

Jump to

Keyboard shortcuts

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