Documentation
¶
Index ¶
- func DeepClone[T any](m T) T
- func KeepKeys[K comparable, V any](m map[K]V, keys ...K) map[K]V
- func RemoveKeys[K comparable, V any](m map[K]V, keys ...K) map[K]V
- func Seq2[K comparable, V any](m map[K]V) iter.Seq2[K, V]
- func WalkMap(m map[string]interface{}, prefix string, f func(k string, v interface{}))
- type ImmutableMap
- type Keyer
- type Result
- func (r Result[T]) Error() error
- func (r Result[T]) FlatMap(mapper func(value T) Result[T]) Result[T]
- func (r Result[T]) ForEach(mapper func(value T))
- func (r Result[T]) Get() (T, error)
- func (r Result[T]) IsError() bool
- func (r Result[T]) IsOk() bool
- func (r Result[T]) Map(mapper func(value T) (T, error)) Result[T]
- func (r Result[T]) MapErr(mapper func(error) (T, error)) Result[T]
- func (o Result[T]) MarshalJSON() ([]byte, error)
- func (r Result[T]) Match(onSuccess func(value T) (T, error), onError func(err error) (T, error)) Result[T]
- func (r Result[T]) MustGet() T
- func (r Result[T]) OrElse(fallback T) T
- func (r Result[T]) OrEmpty() T
- func (o *Result[T]) UnmarshalJSON(data []byte) error
- type Store
- type SyncSet
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func KeepKeys ¶
func KeepKeys[K comparable, V any](m map[K]V, keys ...K) map[K]V
KeepKeys remove all the keys that are NOT in keys from map m
func RemoveKeys ¶
func RemoveKeys[K comparable, V any](m map[K]V, keys ...K) map[K]V
RemoveKeys removes all the keys from map m
Types ¶
type ImmutableMap ¶
type ImmutableMap[K comparable, V any] interface { Get(key K) (V, bool) Keys() iter.Seq[K] Values() iter.Seq[V] IterSeq2() iter.Seq2[K, V] }
func NewImmutableMap ¶
func NewImmutableMap[K comparable, V any](m map[K]V) ImmutableMap[K, V]
type Result ¶
type Result[T any] struct { // contains filtered or unexported fields }
Result represents a result of an action having one of the following output: success or failure. An instance of Result is an instance of either Ok or Err. It could be compared to `Either[error, T]`.
func Do ¶
Do executes a function within a monadic context, capturing any errors that occur. If the function executes successfully, its result is wrapped in a successful Result. If the function panics (indicating a failure), the panic is caught and converted into an error Result.
func Err ¶
Err builds a Result when value is invalid. Play: https://go.dev/play/p/PDwADdzNoyZ
func Errf ¶
Errf builds a Result when value is invalid. Errf formats according to a format specifier and returns the error as a value that satisfies Result[T]. Play: https://go.dev/play/p/N43w92SM-Bs
func Ok ¶
Ok builds a Result when value is valid. Play: https://go.dev/play/p/PDwADdzNoyZ
func Try ¶
Try returns either a Ok or Err object. Play: https://go.dev/play/p/ilOlQx-Mx42
func TupleToResult ¶
TupleToResult convert a pair of T and error into a Result. Play: https://go.dev/play/p/KWjfqQDHQwa
func (Result[T]) Error ¶
Error returns error when value is invalid or nil. Play: https://go.dev/play/p/CSkHGTyiXJ5
func (Result[T]) FlatMap ¶
FlatMap executes the mapper function if Result is valid. It returns a new Result. Play: https://go.dev/play/p/Ud5QjZOqg-7
func (Result[T]) ForEach ¶
func (r Result[T]) ForEach(mapper func(value T))
ForEach executes the given side-effecting function if Result is valid.
func (Result[T]) Get ¶
Get returns value and error. Play: https://go.dev/play/p/8KyX3z6TuNo
func (Result[T]) IsError ¶
IsError returns true when value is invalid. Play: https://go.dev/play/p/xkV9d464scV
func (Result[T]) IsOk ¶
IsOk returns true when value is valid. Play: https://go.dev/play/p/sfNvBQyZfgU
func (Result[T]) Map ¶
Map executes the mapper function if Result is valid. It returns a new Result. Play: https://go.dev/play/p/-ndpN_b_OSc
func (Result[T]) MapErr ¶
MapErr executes the mapper function if Result is invalid. It returns a new Result. Play: https://go.dev/play/p/WraZixg9GGf
func (Result[T]) MarshalJSON ¶
MarshalJSON encodes Result into json, following the JSON-RPC specification for results, with one exception: when the result is an error, the "code" field is not included. Reference: https://www.jsonrpc.org/specification
func (Result[T]) Match ¶
func (r Result[T]) Match(onSuccess func(value T) (T, error), onError func(err error) (T, error)) Result[T]
Match executes the first function if Result is valid and second function if invalid. It returns a new Result. Play: https://go.dev/play/p/-_eFaLJ31co
func (Result[T]) MustGet ¶
func (r Result[T]) MustGet() T
MustGet returns value when Result is valid or panics. Play: https://go.dev/play/p/8LSlndHoTAE
func (Result[T]) OrElse ¶
func (r Result[T]) OrElse(fallback T) T
OrElse returns value when Result is valid or default value. Play: https://go.dev/play/p/MN_ULx0soi6
func (Result[T]) OrEmpty ¶
func (r Result[T]) OrEmpty() T
OrEmpty returns value when Result is valid or empty value. Play: https://go.dev/play/p/rdKtBmOcMLh
func (*Result[T]) UnmarshalJSON ¶
UnmarshalJSON decodes json into Result. If "error" is set, the result is an Err containing the error message as a generic error object. Otherwise, the result is an Ok containing the result. If the JSON object contains netiher an error nor a result, the result is an Ok containing an empty value. If the JSON object contains both an error and a result, the result is an Err. Finally, if the JSON object contains an error but is not structured correctly (no message field), the unmarshaling fails.
type SyncSet ¶
type SyncSet[T comparable] interface { // Set adds a value to the set if it doesn't already exist. // Returns true if the value was added, false if it was already present. Set(v T) bool // All returns an iterator over all values in the set in no particular order. All() iter.Seq[T] }
SyncSet represents a thread-safe set data structure that can store unique comparable values.
func NewSyncSet ¶
func NewSyncSet[T comparable]() SyncSet[T]
NewSyncSet creates a new thread-safe set implementation. The set can store any comparable type T and prevents duplicate entries. It is safe for concurrent access by multiple goroutines.