Documentation
¶
Index ¶
- func FirstOfTwo[T1, T2 any](arg1 T1, _ T2) T1
- func GetCallPlace(skip int) (file string, line int)
- func GetIf[T any](condition bool, resultOnTrue T) (result T)
- func Iif[T any](condition bool, resultOnTrue T, resultOnFalse T) T
- func MakeTypedVar(targetType reflect.Type, initialValue any) any
- func Must[T any](val T, err error) T
- func MustDo(err error)
- func MustMake[T any](val T, err error) T
- func ParseTypedVar(targetType reflect.Type, input any) (result any, err error)
- func ResultDecode[T1, T2 any](input Result[T1], valueDecoder func(src T1) T2) (newVal T2, _ error)
- func ResultDecodeCtxError[T1, T2 any](ctx context.Context, input Result[T1], ...) (newVal T2, _ error)
- func ResultDecodeError[T1, T2 any](input Result[T1], valueDecoder func(src T1) (T2, error)) (newVal T2, _ error)
- func SecondOfTwo[T1, T2 any](_ T1, arg2 T2) T2
- func SliceToSlice[FROM, TO any](source []FROM, converter func(FROM) TO) []TO
- func SliceToSliceError[FROM, TO any](source []FROM, converter func(FROM) (TO, error)) (result []TO, err error)
- func SplitCamelCase(s string) []string
- func ToKebabCase(s string) string
- func ToSnakeCase(s string) string
- type Nothing
- type Option
- type Result
- type SyncSlice
- func (s *SyncSlice[T]) Append(val T)
- func (s *SyncSlice[T]) Get(index int) (val T)
- func (s *SyncSlice[T]) InitSize(length, capacity int)
- func (s *SyncSlice[T]) Len() int
- func (s *SyncSlice[T]) Seq() iter.Seq[T]
- func (s *SyncSlice[T]) Seq2() iter.Seq2[int, T]
- func (s *SyncSlice[T]) Set(index int, val T)
- func (s *SyncSlice[T]) Values() []T
- type SyncStore
- func (s *SyncStore[K, V]) Del(key K)
- func (s *SyncStore[K, V]) ForEach(handler func(key K, value V))
- func (s *SyncStore[K, V]) GetCurrent(key K) (val V, founded bool)
- func (s *SyncStore[K, V]) GetOrPut(key K, maker func() V) V
- func (s *SyncStore[K, V]) Iterator() ...
- func (s *SyncStore[K, V]) Preallocate(mapSize int)
- func (s *SyncStore[K, V]) Put(key K, val V)
- func (s *SyncStore[K, V]) Seq() func(yield func(V) bool)
- func (s *SyncStore[K, V]) Seq2() func(yield func(K, V) bool)
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FirstOfTwo ¶ added in v1.0.29
func FirstOfTwo[T1, T2 any](arg1 T1, _ T2) T1
func GetCallPlace ¶ added in v1.0.14
func GetIf ¶ added in v1.0.20
GetIf - returns the second argument if the condition is true, default value otherwise. Designed to replace the "var+if" block.
Example ¶
package main
import (
"fmt"
"time"
"github.com/mirrorru/dot"
)
func main() {
cond := time.Now().IsZero()
// Long way
var aLongWay, bLongWay int
if cond {
aLongWay = 1
}
if !cond {
bLongWay = 1
}
// Short way
aShortWay := dot.GetIf(cond, 2)
bShortWay := dot.GetIf(!cond, 2)
fmt.Println(aLongWay, bLongWay, aShortWay, bShortWay)
}
Output: 0 1 0 2
func Iif ¶
Iif - inline "if".
Example ¶
package main
import (
"fmt"
"github.com/mirrorru/dot"
)
func main() {
for i := range 4 {
fmt.Println(dot.Iif(i%2 == 0, "Even", "Odd"))
}
}
Output: Even Odd Even Odd
func MakeTypedVar ¶ added in v1.0.30
func MustDo ¶ added in v1.0.15
func MustDo(err error)
MustDo - checks that the argument is not an error, otherwise it panics. Usually, the argument is passed directly as the result of calling another method.
Example ¶
package main
import (
"fmt"
"github.com/mirrorru/dot"
)
func main() {
dot.MustDo(func() error {
fmt.Println("No error inside call")
return nil
}())
}
Output: No error inside call
func MustMake ¶ added in v1.0.15
MustMake - checks that the second argument is not an error then return first argument, otherwise it panics Usually, the arguments is passed directly as the result of calling another method.
Example ¶
package main
import (
"fmt"
"github.com/mirrorru/dot"
)
func main() {
s := dot.MustMake(func() (string, error) {
return "The created string", nil
}())
fmt.Println(s)
}
Output: The created string
func ParseTypedVar ¶ added in v1.0.30
ParseTypedVar parses a any into a value of the specified reflect.Type and returns it as any. Returns nil and an error if parsing fails or the type is unsupported. If the type implements Scanner, it uses the Scan method for parsing.
func ResultDecode ¶ added in v1.0.33
func ResultDecodeCtxError ¶ added in v1.0.34
func ResultDecodeError ¶ added in v1.0.33
func SecondOfTwo ¶ added in v1.0.29
func SecondOfTwo[T1, T2 any](_ T1, arg2 T2) T2
func SliceToSlice ¶ added in v1.0.26
func SliceToSlice[FROM, TO any](source []FROM, converter func(FROM) TO) []TO
SliceToSlice - converts slice to new type slice
func SliceToSliceError ¶ added in v1.0.26
func SplitCamelCase ¶ added in v1.0.26
SplitCamelCase разбивает строку по смене регистра
func ToKebabCase ¶ added in v1.0.26
func ToSnakeCase ¶ added in v1.0.26
Types ¶
type Result ¶
type Result[T any] struct { // contains filtered or unexported fields }
Result holds operation result - some value and error
func CastResult ¶ added in v1.0.19
CastResult - casts any to specified type or return error
func MakeResult ¶ added in v1.0.6
MakeResult maker Result from arguments
func TransformCtxResult ¶ added in v1.0.34
func TransformCtxResult[T1, T2 any](ctx context.Context, res Result[T1], converter func(ctx context.Context, src T1) (T2, error)) Result[T2]
TransformCtxResult - make new `Result[T2]` from `Result[T1]` by `func(ctx, T1)Result[T2]`
func TransformResult ¶ added in v1.0.33
TransformResult - make new `Result[T2]` from `Result[T1]` by `func(T1)Result[T2]`
func (Result[T]) OrElse ¶ added in v1.0.6
func (r Result[T]) OrElse(anotherVal T) T
OrElse return argument value, if result have error
func (Result[T]) OrEmpty ¶ added in v1.0.6
func (r Result[T]) OrEmpty() (empty T)
OrEmpty return default (empty) value, if result have error.
type SyncSlice ¶ added in v1.0.7
type SyncSlice[T any] struct { // contains filtered or unexported fields }
type SyncStore ¶ added in v1.0.22
type SyncStore[K comparable, V any] struct { // contains filtered or unexported fields }
func (*SyncStore[K, V]) ForEach ¶ added in v1.0.22
func (s *SyncStore[K, V]) ForEach(handler func(key K, value V))
ForEach вызывает handler для каждой пары ключ-значение
func (*SyncStore[K, V]) GetCurrent ¶ added in v1.0.23
func (*SyncStore[K, V]) GetOrPut ¶ added in v1.0.23
func (s *SyncStore[K, V]) GetOrPut(key K, maker func() V) V
func (*SyncStore[K, V]) Iterator ¶ added in v1.0.22
func (s *SyncStore[K, V]) Iterator() <-chan struct { Key K Value V }
func (*SyncStore[K, V]) Preallocate ¶ added in v1.0.22
Preallocate - init internal map with specified size