Documentation
¶
Index ¶
- Variables
- func FirstVal[T any](v ...*T) *T
- func Generator[T any](ctx context.Context, size int, ...) <-chan T
- func GeneratorSimple[T any](size int, genFn func(prev T) (T, bool)) <-chan T
- func MapEqual[T ~map[K]V, K comparable, V comparable](mp, otherMap T) bool
- func MapReduce[K comparable, V any, R any](mp map[K]V, reduce func(key K, val V, ret *R)) R
- func Max[T constraints.Ordered](x, y T) T
- func Min[T constraints.Ordered](x, y T) T
- func SliceReduce[T any, R any](sl []T, reduce func(val T, ret *R)) R
- func SliceUnique[T comparable](sl []T) []T
- type Any
- func (a *Any) Bool() bool
- func (a *Any) Float64() float64
- func (a *Any) Get() any
- func (a *Any) GetOr(def any) any
- func (a *Any) Int() int
- func (a *Any) Int64() int64
- func (a *Any) IsEmpty() bool
- func (a *Any) IsNil() bool
- func (a *Any) Set(val any) error
- func (a *Any) String() string
- func (a *Any) TryBool() (bool, error)
- func (a *Any) TryFloat64() (float64, error)
- func (a *Any) TryInt() (int, error)
- func (a *Any) TryInt64() (int64, error)
- func (a *Any) TryString() (string, error)
- func (a *Any) TryUint() (uint, error)
- func (a *Any) TryUint64() (uint64, error)
- func (a *Any) Uint() uint
- func (a *Any) Uint64() uint64
- type LazySlice
- type Map
- func (mp Map[K, V]) Apply(apply func(key K, val V) (K, V)) Map[K, V]
- func (mp Map[K, V]) Copy() Map[K, V]
- func (mp Map[K, V]) Each(iter func(key K, val V)) Map[K, V]
- func (mp Map[K, V]) Filter(filter func(key K, val V) bool) Map[K, V]
- func (mp Map[K, V]) Keys() Slice[K]
- func (mp Map[K, V]) Merge(maps ...Map[K, V]) Map[K, V]
- func (mp Map[K, V]) MergeConflict(conflictFunc func(V, V) V, maps ...Map[K, V]) Map[K, V]
- func (mp Map[K, V]) ReduceIntoOne(reduce func(key K, val V, ret *V)) V
- func (mp Map[K, V]) Set(key K, val V) Map[K, V]
- func (mp Map[K, V]) Values() Slice[V]
- type Slice
- func (sl Slice[T]) Append(val T) Slice[T]
- func (sl Slice[T]) Apply(apply func(val T) T) Slice[T]
- func (sl Slice[T]) BinarySearch(fn func(val T) bool) int
- func (sl Slice[T]) Copy() Slice[T]
- func (sl Slice[T]) Each(iter func(val T)) Slice[T]
- func (sl Slice[T]) Filter(filter func(val T) bool) Slice[T]
- func (sl Slice[T]) First() *T
- func (sl Slice[T]) FirstOr(def T) T
- func (sl Slice[T]) Has(fn func(val T) bool) bool
- func (sl Slice[T]) IndexOf(fn func(val T) bool) int
- func (sl Slice[T]) Last() *T
- func (sl Slice[T]) LastOr(def T) T
- func (sl Slice[T]) Len() int
- func (sl Slice[T]) Prepend(val T) Slice[T]
- func (sl Slice[T]) ReduceIntoOne(apply func(val T, ret *T)) T
- func (sl Slice[T]) RemoveAt(i int) Slice[T]
- func (sl Slice[T]) RemoveRange(i, j int) Slice[T]
- func (sl Slice[T]) Sort(cmp func(a, b T) bool) Slice[T]
- func (sl Slice[T]) ValueOr(i int, def T) T
Constants ¶
This section is empty.
Variables ¶
var (
ErrBoxContainerIsNil = errors.New("container is nil")
)
Functions ¶
func Generator ¶
func Generator[T any](ctx context.Context, size int, genFn func(ctx context.Context, prev T) (T, bool)) <-chan T
Generator returns generator with context Done support
func GeneratorSimple ¶
GeneratorSimple returns generator which is not controlled from external
func MapEqual ¶
func MapEqual[T ~map[K]V, K comparable, V comparable](mp, otherMap T) bool
MapEqual comparing two maps of the same type
func MapReduce ¶
func MapReduce[K comparable, V any, R any](mp map[K]V, reduce func(key K, val V, ret *R)) R
MapReduce map and return new value
func Max ¶
func Max[T constraints.Ordered](x, y T) T
Max value Deprecated: use `max` in go1.21+ instead.
func Min ¶
func Min[T constraints.Ordered](x, y T) T
Min value Deprecated: use `min` in go1.21+ instead.
func SliceReduce ¶
SliceReduce slice and return new value
func SliceUnique ¶
func SliceUnique[T comparable](sl []T) []T
SliceUnique return new slice without duplicated values
Types ¶
type Any ¶ added in v0.3.0
type Any struct {
Val any
}
Any is a type alias for any.
func (*Any) Bool ¶ added in v0.3.0
Bool retrieves the value of the Any instance as a boolean. It uses the gocast.Bool function to convert the value to a boolean. It returns false if the Any instance is nil or if the value cannot be converted to a boolean. Otherwise, it returns the converted boolean value.
func (*Any) Float64 ¶ added in v0.3.0
Float64 retrieves the value of the Any instance as a 64-bit floating-point number. It uses the gocast.Number function to convert the value to a 64-bit floating-point number. It returns 0 if the Any instance is nil or if the value cannot be converted to a 64-bit floating-point number. Otherwise, it returns the converted 64-bit floating-point number.
func (*Any) Get ¶ added in v0.3.0
Get retrieves the value of the Any instance. It returns nil if the Any instance is nil. Otherwise, it returns the value.
func (*Any) GetOr ¶ added in v0.3.0
GetOr retrieves the value of the Any instance or returns a default value. It returns the value if the Any instance is not nil, otherwise it returns the default value.
func (*Any) Int ¶ added in v0.3.0
Int retrieves the value of the Any instance as an integer. It uses the gocast.Number function to convert the value to an integer. It returns 0 if the Any instance is nil or if the value cannot be converted to an integer. Otherwise, it returns the converted integer value. It also returns an error if the conversion fails.
func (*Any) Int64 ¶ added in v0.3.0
Int64 retrieves the value of the Any instance as a 64-bit integer. It uses the gocast.Number function to convert the value to a 64-bit integer. It returns 0 if the Any instance is nil or if the value cannot be converted to a 64-bit integer. Otherwise, it returns the converted 64-bit integer value.
func (*Any) IsEmpty ¶ added in v0.3.0
IsEmpty checks if the value is empty. It uses the gocast.IsEmpty function to determine if the value is empty. It returns true if the value is empty, otherwise false. It also checks if the Any instance itself is nil.
func (*Any) IsNil ¶ added in v0.3.0
IsNil checks if the value is nil. It returns true if the value is nil, otherwise false.
func (*Any) Set ¶ added in v0.3.0
Set sets the value of the Any instance. It returns an error if the Any instance is nil. Otherwise, it sets the value and returns nil.
func (*Any) String ¶ added in v0.3.0
String retrieves the value of the Any instance as a string. It uses the gocast.String function to convert the value to a string. It returns an empty string if the Any instance is nil or if the value cannot be converted to a string. Otherwise, it returns the converted string value.
func (*Any) TryBool ¶ added in v0.3.0
TryBool attempts to retrieve the value of the Any instance as a boolean. It uses the gocast.TryCast function to convert the value to a boolean. It returns an error if the Any instance is nil or if the value cannot be converted to a boolean. Otherwise, it returns the converted boolean value. It also returns an error if the conversion fails.
func (*Any) TryFloat64 ¶ added in v0.3.0
TryFloat64 attempts to retrieve the value of the Any instance as a 64-bit floating-point number. It uses the gocast.TryNumber function to convert the value to a 64-bit floating-point number. It returns an error if the Any instance is nil or if the value cannot be converted to a 64-bit floating-point number. Otherwise, it returns the converted 64-bit floating-point number. It also returns an error if the conversion fails.
func (*Any) TryInt ¶ added in v0.3.0
TryInt attempts to retrieve the value of the Any instance as an integer. It uses the gocast.TryNumber function to convert the value to an integer. It returns an error if the Any instance is nil or if the value cannot be converted to an integer. Otherwise, it returns the converted integer value. It also returns an error if the conversion fails.
func (*Any) TryInt64 ¶ added in v0.3.0
TryInt64 attempts to retrieve the value of the Any instance as a 64-bit integer. It uses the gocast.TryNumber function to convert the value to a 64-bit integer. It returns an error if the Any instance is nil or if the value cannot be converted to a 64-bit integer. Otherwise, it returns the converted 64-bit integer value. It also returns an error if the conversion fails.
func (*Any) TryString ¶ added in v0.3.0
TryString attempts to retrieve the value of the Any instance as a string. It uses the gocast.TryStr function to convert the value to a string. It returns an error if the Any instance is nil or if the value cannot be converted to a string. Otherwise, it returns the converted string value. It also returns an error if the conversion fails.
func (*Any) TryUint ¶ added in v0.3.0
TryUint attempts to retrieve the value of the Any instance as an unsigned integer.
func (*Any) TryUint64 ¶ added in v0.3.0
TryUint64 attempts to retrieve the value of the Any instance as a 64-bit unsigned integer. It uses the gocast.TryNumber function to convert the value to a 64-bit unsigned integer. It returns an error if the Any instance is nil or if the value cannot be converted to a 64-bit unsigned integer. Otherwise, it returns the converted 64-bit unsigned integer value. It also returns an error if the conversion fails.
func (*Any) Uint ¶ added in v0.3.0
Uint retrieves the value of the Any instance as an unsigned integer. It uses the gocast.Number function to convert the value to an unsigned integer. It returns 0 if the Any instance is nil or if the value cannot be converted to an unsigned integer. Otherwise, it returns the converted unsigned integer value.
func (*Any) Uint64 ¶ added in v0.3.0
Uint64 retrieves the value of the Any instance as a 64-bit unsigned integer. It uses the gocast.Number function to convert the value to a 64-bit unsigned integer. It returns 0 if the Any instance is nil or if the value cannot be converted to a 64-bit unsigned integer. Otherwise, it returns the converted 64-bit unsigned integer value.
type LazySlice ¶
type LazySlice[T any] struct { // contains filtered or unexported fields }
LazySlice type extended with banch of processing methods
func NewLazySlice ¶
NewLazySlice creates new lazy slice
type Map ¶
type Map[K comparable, V any] map[K]V
Map type extended with banch of processing methods
func MapApply ¶
func MapApply[K comparable, V any, NK comparable, NV any](mp map[K]V, apply func(key K, val V) (NK, NV)) Map[NK, NV]
AmpApply the function to each element of the map
func (Map[K, V]) MergeConflict ¶ added in v0.2.0
MergeConflict maps into one with conflict function resolver
func (Map[K, V]) ReduceIntoOne ¶
func (mp Map[K, V]) ReduceIntoOne(reduce func(key K, val V, ret *V)) V
ReduceIntoOne map and return single value
type Slice ¶
type Slice[T any] []T
Slice type extended with banch of processing methods
func SliceApply ¶
SliceApply the function to each element of the slice
func (Slice[T]) BinarySearch ¶
BinarySearch slice values
func (Slice[T]) FirstOr ¶
func (sl Slice[T]) FirstOr(def T) T
FirstOr value from slice or default value
func (Slice[T]) LastOr ¶
func (sl Slice[T]) LastOr(def T) T
LastOr value from slice or default value
func (Slice[T]) ReduceIntoOne ¶
func (sl Slice[T]) ReduceIntoOne(apply func(val T, ret *T)) T
ReduceIntoOne slice and return new single value
func (Slice[T]) RemoveRange ¶
RemoveRange values from slice