Documentation
¶
Overview ¶
Package dict provides generic functions for working with maps.
This package offers type-safe operations on Go maps, including safe value retrieval, key/value extraction, filtering, and transformation operations.
Examples ¶
// Safe value retrieval
m := map[string]int{"a": 1, "b": 2}
value := dict.Get(m, "a")
if value.IsSome() {
fmt.Println(value.Unwrap()) // Output: 1
}
// Extract keys
keys := dict.Keys(m) // []string{"a", "b"}
// Filter map
filtered := dict.Filter(m, func(k string, v int) bool {
return v > 1
}) // map[string]int{"b": 2}
Index ¶
- func Copy[K comparable, V any](m map[K]V) map[K]V
- func Every[K comparable, V any](m map[K]V, fn func(k K, v V) bool) bool
- func Filter[K comparable, V any](m map[K]V, fn func(K, V) bool) map[K]V
- func FilterMap[K comparable, V any, K2 comparable, V2 any](m map[K]V, fn func(K, V) option.Option[DictEntry[K2, V2]]) map[K2]V2
- func FilterMapKey[K comparable, V any, K2 comparable](m map[K]V, fn func(K, V) option.Option[DictEntry[K2, V]]) map[K2]V
- func FilterMapValue[K comparable, V any, V2 any](m map[K]V, fn func(K, V) option.Option[DictEntry[K, V2]]) map[K]V2
- func Find[K comparable, V any](m map[K]V, fn func(K, V) bool) option.Option[DictEntry[K, V]]
- func Get[K comparable, V any](m map[K]V, k K) option.Option[V]
- func Keys[K comparable, V any](m map[K]V) []K
- func Map[K comparable, V any, K2 comparable, V2 any](m map[K]V, mapping func(K, V) DictEntry[K2, V2]) map[K2]V2
- func MapCurry[K comparable, V any, K2 comparable, V2 any](m map[K]V, keyMapping func(K) K2) func(valueMapping func(V) V2) map[K2]V2
- func MapKey[K comparable, V any, K2 comparable](m map[K]V, mapping func(K, V) K2) map[K2]V
- func MapKeyAlone[K comparable, V any, K2 comparable](m map[K]V, mapping func(K) K2) map[K2]V
- func MapValue[K comparable, V any, V2 any](m map[K]V, mapping func(K, V) V2) map[K]V2
- func MapValueAlone[K comparable, V any, V2 any](m map[K]V, mapping func(V) V2) map[K]V2
- func Some[K comparable, V any](m map[K]V, fn func(K, V) bool) bool
- func Values[K comparable, V any](m map[K]V) []V
- func Vec[K comparable, V any, T any](m map[K]V, set func(K, V) T) []T
- type DictEntry
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Every ¶
func Every[K comparable, V any](m map[K]V, fn func(k K, v V) bool) bool
Every tests whether all entries in the map pass the test implemented by the provided function. NOTE:
Calling this method on an empty map will return true for any condition!
func Filter ¶
func Filter[K comparable, V any](m map[K]V, fn func(K, V) bool) map[K]V
Filter creates a new map with all elements that pass the test implemented by the provided function.
func FilterMap ¶
func FilterMap[K comparable, V any, K2 comparable, V2 any](m map[K]V, fn func(K, V) option.Option[DictEntry[K2, V2]]) map[K2]V2
FilterMap returns a filtered and mapped map of new entries.
func FilterMapKey ¶
func FilterMapKey[K comparable, V any, K2 comparable](m map[K]V, fn func(K, V) option.Option[DictEntry[K2, V]]) map[K2]V
FilterMapKey returns a filtered and mapped map of new entries.
func FilterMapValue ¶
func FilterMapValue[K comparable, V any, V2 any](m map[K]V, fn func(K, V) option.Option[DictEntry[K, V2]]) map[K]V2
FilterMapValue returns a filtered and mapped map of new entries.
func Get ¶ added in v1.5.0
func Get[K comparable, V any](m map[K]V, k K) option.Option[V]
Get returns the option.Option[V] of the entry for the provided key.
func Map ¶
func Map[K comparable, V any, K2 comparable, V2 any](m map[K]V, mapping func(K, V) DictEntry[K2, V2]) map[K2]V2
Map creates a new map populated with the results of calling a provided function on every entry in the calling map.
func MapCurry ¶
func MapCurry[K comparable, V any, K2 comparable, V2 any](m map[K]V, keyMapping func(K) K2) func(valueMapping func(V) V2) map[K2]V2
MapCurry creates a new map populated with the results of calling a provided function on every entry in the calling map.
func MapKey ¶
func MapKey[K comparable, V any, K2 comparable](m map[K]V, mapping func(K, V) K2) map[K2]V
MapKey creates a new map populated with the results of calling a provided function on every entry in the calling map.
func MapKeyAlone ¶
func MapKeyAlone[K comparable, V any, K2 comparable](m map[K]V, mapping func(K) K2) map[K2]V
MapKeyAlone creates a new map populated with the results of calling a provided function on every entry in the calling map.
func MapValue ¶
func MapValue[K comparable, V any, V2 any](m map[K]V, mapping func(K, V) V2) map[K]V2
MapValue creates a new map populated with the results of calling a provided function on every entry in the calling map.
func MapValueAlone ¶
func MapValueAlone[K comparable, V any, V2 any](m map[K]V, mapping func(V) V2) map[K]V2
MapValueAlone creates a new map populated with the results of calling a provided function on every entry in the calling map.
func Some ¶
func Some[K comparable, V any](m map[K]V, fn func(K, V) bool) bool
Some tests whether at least one entry in the map passes the test implemented by the provided function. NOTE:
Calling this method on an empty map returns false for any condition!
func Vec ¶ added in v1.5.0
func Vec[K comparable, V any, T any](m map[K]V, set func(K, V) T) []T
Vec generates an orderless slice through the set function.
Types ¶
type DictEntry ¶ added in v1.20.0
type DictEntry[K comparable, V any] struct { Key K Value V }
DictEntry is a key-value entry of map.
func Entries ¶
func Entries[K comparable, V any](m map[K]V) []DictEntry[K, V]
Entries returns the entries of map.