Documentation ¶
Overview ¶
Package aghalg contains common generic algorithms and data structures.
TODO(a.garipov): Move parts of this into golibs.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Coalesce ¶
func Coalesce[T comparable](values ...T) (res T)
Coalesce returns the first non-zero value. It is named after function COALESCE in SQL. If values or all its elements are empty, it returns a zero value.
T is comparable, because Go currently doesn't have a comparableWithZeroValue constraint.
TODO(a.garipov): Think of ways to merge with CoalesceSlice.
func CoalesceSlice ¶
func CoalesceSlice[E any, S []E](values ...S) (res S)
CoalesceSlice returns the first non-zero value. It is named after function COALESCE in SQL. If values or all its elements are empty, it returns nil.
TODO(a.garipov): Think of ways to merge with Coalesce.
Types ¶
type NullBool ¶
type NullBool uint8
NullBool is a nullable boolean. Use these in JSON requests and responses instead of pointers to bool.
func BoolToNullBool ¶
BoolToNullBool converts a bool into a NullBool.
func (NullBool) MarshalJSON ¶
MarshalJSON implements the json.Marshaler interface for NullBool.
func (*NullBool) UnmarshalJSON ¶
UnmarshalJSON implements the json.Unmarshaler interface for *NullBool.
type UniqChecker ¶
type UniqChecker[T constraints.Ordered] map[T]int64
UniqChecker allows validating uniqueness of comparable items.
TODO(a.garipov): The Ordered constraint is only really necessary in Validate. Consider ways of making this constraint comparable instead.
func (UniqChecker[T]) Add ¶
func (uc UniqChecker[T]) Add(elems ...T)
Add adds a value to the validator. v must not be nil.
func (UniqChecker[T]) Merge ¶
func (uc UniqChecker[T]) Merge(other UniqChecker[T]) (merged UniqChecker[T])
Merge returns a checker containing data from both uc and other.
func (UniqChecker[T]) Validate ¶
func (uc UniqChecker[T]) Validate() (err error)
Validate returns an error enumerating all elements that aren't unique.