dot

package module
v1.0.35 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2025 License: MIT Imports: 10 Imported by: 2

README

dot

Developer’s Optimization Toolkit

Documentation

Index

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 GetCallPlace(skip int) (file string, line int)

func GetIf added in v1.0.20

func GetIf[T any](condition bool, resultOnTrue T) (result T)

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

func Iif[T any](condition bool, resultOnTrue T, resultOnFalse T) T

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 MakeTypedVar(targetType reflect.Type, initialValue any) any

func Must added in v1.0.14

func Must[T any](val T, err error) T

Must - equivalent to MustMake.

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

func MustMake[T any](val T, err error) T

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

func ParseTypedVar(targetType reflect.Type, input any) (result any, err error)

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 ResultDecode[T1, T2 any](input Result[T1], valueDecoder func(src T1) T2) (newVal T2, _ error)

func ResultDecodeCtxError added in v1.0.34

func ResultDecodeCtxError[T1, T2 any](ctx context.Context, input Result[T1], valueDecoder func(ctx context.Context, src T1) (T2, error)) (newVal T2, _ error)

func ResultDecodeError added in v1.0.33

func ResultDecodeError[T1, T2 any](input Result[T1], valueDecoder func(src T1) (T2, error)) (newVal T2, _ error)

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 SliceToSliceError[FROM, TO any](source []FROM, converter func(FROM) (TO, error)) (result []TO, err error)

func SplitCamelCase added in v1.0.26

func SplitCamelCase(s string) []string

SplitCamelCase разбивает строку по смене регистра

func ToKebabCase added in v1.0.26

func ToKebabCase(s string) string

func ToSnakeCase added in v1.0.26

func ToSnakeCase(s string) string

Types

type Nothing added in v1.0.15

type Nothing struct{}

type Option

type Option[T any] struct {
	Val T
	Ok  bool
}

func ToOption added in v1.0.31

func ToOption[T any](input T) Option[T]

func ToOptionEmpty added in v1.0.35

func ToOptionEmpty[T any](input T) Option[T]

func ToOptionPtr added in v1.0.35

func ToOptionPtr[T any, PT *T](input PT) Option[T]

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

func CastResult[T any](src Result[any]) Result[T]

CastResult - casts any to specified type or return error

func MakeResult added in v1.0.6

func MakeResult[T any](val T, err error) Result[T]

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

func TransformResult[T1, T2 any](res Result[T1], converter func(src T1) (T2, error)) Result[T2]

TransformResult - make new `Result[T2]` from `Result[T1]` by `func(T1)Result[T2]`

func (Result[T]) Err

func (r Result[T]) Err() error

Err returns inner error

func (Result[T]) IsErr added in v1.0.6

func (r Result[T]) IsErr() bool

IsErr reports about not nil inner error

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.

func (Result[T]) SaveVal added in v1.0.17

func (r Result[T]) SaveVal(dest any) Result[T]

SaveVal writes inner value to reference

func (Result[T]) ToOption added in v1.0.6

func (r Result[T]) ToOption() Option[T]

ToOption - converts Result to Option type

func (Result[T]) Unwarp added in v1.0.6

func (r Result[T]) Unwarp() (T, error)

Unwarp extracts value and error

func (Result[T]) Val added in v1.0.6

func (r Result[T]) Val() T

Val returns inner value

type SyncSlice added in v1.0.7

type SyncSlice[T any] struct {
	// contains filtered or unexported fields
}

func (*SyncSlice[T]) Append added in v1.0.7

func (s *SyncSlice[T]) Append(val T)

func (*SyncSlice[T]) Get added in v1.0.7

func (s *SyncSlice[T]) Get(index int) (val T)

func (*SyncSlice[T]) InitSize added in v1.0.7

func (s *SyncSlice[T]) InitSize(length, capacity int)

func (*SyncSlice[T]) Len added in v1.0.10

func (s *SyncSlice[T]) Len() int

func (*SyncSlice[T]) Seq added in v1.0.13

func (s *SyncSlice[T]) Seq() iter.Seq[T]

func (*SyncSlice[T]) Seq2 added in v1.0.13

func (s *SyncSlice[T]) Seq2() iter.Seq2[int, T]

func (*SyncSlice[T]) Set added in v1.0.7

func (s *SyncSlice[T]) Set(index int, val T)

func (*SyncSlice[T]) Values added in v1.0.7

func (s *SyncSlice[T]) Values() []T

type SyncStore added in v1.0.22

type SyncStore[K comparable, V any] struct {
	// contains filtered or unexported fields
}

func (*SyncStore[K, V]) Del added in v1.0.22

func (s *SyncStore[K, V]) Del(key K)

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 (s *SyncStore[K, V]) GetCurrent(key K) (val V, founded bool)

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

func (s *SyncStore[K, V]) Preallocate(mapSize int)

Preallocate - init internal map with specified size

func (*SyncStore[K, V]) Put added in v1.0.23

func (s *SyncStore[K, V]) Put(key K, val V)

func (*SyncStore[K, V]) Seq added in v1.0.22

func (s *SyncStore[K, V]) Seq() func(yield func(V) bool)

Seq реализует iter.Seq (итерация по значениям)

func (*SyncStore[K, V]) Seq2 added in v1.0.22

func (s *SyncStore[K, V]) Seq2() func(yield func(K, V) bool)

Seq2 реализует iter.Seq2 (итерация по ключу и значению)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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