Documentation
¶
Overview ¶
Package record contains monadic operations for maps as well as a rich set of utility functions
Index ¶
- func Ap[A any, K comparable, B any](m Mo.Monoid[map[K]B]) func(fa map[K]A) func(map[K]func(A) B) map[K]B
- func ApS[S1, T any, K comparable, S2 any](m Mo.Monoid[map[K]S2]) func(setter func(T) func(S1) S2, fa map[K]T) func(map[K]S1) map[K]S2
- func Bind[S1, T any, K comparable, S2 any](m Mo.Monoid[map[K]S2]) func(setter func(T) func(S1) S2, f func(S1) map[K]T) func(map[K]S1) map[K]S2
- func BindTo[S1, T any, K comparable](setter func(T) S1) func(map[K]T) map[K]S1
- func Chain[V1 any, K comparable, V2 any](m Mo.Monoid[map[K]V2]) func(func(V1) map[K]V2) func(map[K]V1) map[K]V2
- func ChainWithIndex[V1 any, K comparable, V2 any](m Mo.Monoid[map[K]V2]) func(func(K, V1) map[K]V2) func(map[K]V1) map[K]V2
- func Clone[K comparable, V any](f EM.Endomorphism[V]) EM.Endomorphism[map[K]V]
- func Collect[K comparable, V, R any](f func(K, V) R) func(map[K]V) []R
- func CollectOrd[V, R any, K comparable](o ord.Ord[K]) func(func(K, V) R) func(map[K]V) []R
- func ConstNil[K comparable, V any]() map[K]V
- func Copy[K comparable, V any](m map[K]V) map[K]V
- func DeleteAt[K comparable, V any](k K) func(map[K]V) map[K]V
- func Do[K comparable, S any]() map[K]S
- func Empty[K comparable, V any]() map[K]V
- func Eq[K comparable, V any](e E.Eq[V]) E.Eq[map[K]V]
- func Filter[K comparable, V any](f func(K) bool) func(map[K]V) map[K]V
- func FilterChain[V1 any, K comparable, V2 any](m Mo.Monoid[map[K]V2]) func(func(V1) O.Option[map[K]V2]) func(map[K]V1) map[K]V2
- func FilterChainWithIndex[V1 any, K comparable, V2 any](m Mo.Monoid[map[K]V2]) func(func(K, V1) O.Option[map[K]V2]) func(map[K]V1) map[K]V2
- func FilterMap[K comparable, V1, V2 any](f func(V1) O.Option[V2]) func(map[K]V1) map[K]V2
- func FilterMapWithIndex[K comparable, V1, V2 any](f func(K, V1) O.Option[V2]) func(map[K]V1) map[K]V2
- func FilterWithIndex[K comparable, V any](f func(K, V) bool) func(map[K]V) map[K]V
- func Flap[B any, K comparable, A any](a A) func(map[K]func(A) B) map[K]B
- func Flatten[K comparable, V any](m Mo.Monoid[map[K]V]) func(map[K]map[K]V) map[K]V
- func Fold[K comparable, A any](m Mo.Monoid[A]) func(map[K]A) A
- func FoldMap[K comparable, A, B any](m Mo.Monoid[B]) func(func(A) B) func(map[K]A) B
- func FoldMapOrd[A, B any, K comparable](o ord.Ord[K]) func(m Mo.Monoid[B]) func(func(A) B) func(map[K]A) B
- func FoldMapOrdWithIndex[K comparable, A, B any](o ord.Ord[K]) func(m Mo.Monoid[B]) func(func(K, A) B) func(map[K]A) B
- func FoldMapWithIndex[K comparable, A, B any](m Mo.Monoid[B]) func(func(K, A) B) func(map[K]A) B
- func FoldOrd[A any, K comparable](o ord.Ord[K]) func(m Mo.Monoid[A]) func(map[K]A) A
- func FromArray[K comparable, V any](m Mg.Magma[V]) func(fa []T.Tuple2[K, V]) map[K]V
- func FromArrayMap[A any, K comparable, V any](m Mg.Magma[V]) func(f func(A) T.Tuple2[K, V]) func(fa []A) map[K]V
- func FromEntries[K comparable, V any](fa []T.Tuple2[K, V]) map[K]V
- func FromFoldable[HKTA any, ...](m Mg.Magma[V], red FOLDABLE) func(fa HKTA) map[K]V
- func FromFoldableMap[FOLDABLE ~func(func(map[K]V, A) map[K]V, map[K]V) func(HKTA) map[K]V, A any, ...](m Mg.Magma[V], red FOLDABLE) func(f func(A) T.Tuple2[K, V]) func(fa HKTA) map[K]V
- func Has[K comparable, V any](k K, r map[K]V) bool
- func IsEmpty[K comparable, V any](r map[K]V) bool
- func IsNil[K comparable, V any](m map[K]V) bool
- func IsNonEmpty[K comparable, V any](r map[K]V) bool
- func IsNonNil[K comparable, V any](m map[K]V) bool
- func Keys[K comparable, V any](r map[K]V) []K
- func KeysOrd[V any, K comparable](o ord.Ord[K]) func(r map[K]V) []K
- func Let[S1, T any, K comparable, S2 any](setter func(T) func(S1) S2, f func(S1) T) func(map[K]S1) map[K]S2
- func LetTo[S1, T any, K comparable, S2 any](setter func(T) func(S1) S2, b T) func(map[K]S1) map[K]S2
- func Lookup[V any, K comparable](k K) func(map[K]V) O.Option[V]
- func Map[K comparable, V, R any](f func(V) R) func(map[K]V) map[K]R
- func MapRef[K comparable, V, R any](f func(*V) R) func(map[K]V) map[K]R
- func MapRefWithIndex[K comparable, V, R any](f func(K, *V) R) func(map[K]V) map[K]R
- func MapWithIndex[K comparable, V, R any](f func(K, V) R) func(map[K]V) map[K]R
- func Merge[K comparable, V any](right map[K]V) func(map[K]V) map[K]V
- func MergeMonoid[K comparable, V any]() M.Monoid[map[K]V]
- func MonadAp[A any, K comparable, B any](m Mo.Monoid[map[K]B], fab map[K]func(A) B, fa map[K]A) map[K]B
- func MonadChain[V1 any, K comparable, V2 any](m Mo.Monoid[map[K]V2], r map[K]V1, f func(V1) map[K]V2) map[K]V2
- func MonadChainWithIndex[V1 any, K comparable, V2 any](m Mo.Monoid[map[K]V2], r map[K]V1, f func(K, V1) map[K]V2) map[K]V2
- func MonadFlap[B any, K comparable, A any](fab map[K]func(A) B, a A) map[K]B
- func MonadLookup[V any, K comparable](m map[K]V, k K) O.Option[V]
- func MonadMap[K comparable, V, R any](r map[K]V, f func(V) R) map[K]R
- func MonadMapRef[K comparable, V, R any](r map[K]V, f func(*V) R) map[K]R
- func MonadMapRefWithIndex[K comparable, V, R any](r map[K]V, f func(K, *V) R) map[K]R
- func MonadMapWithIndex[K comparable, V, R any](r map[K]V, f func(K, V) R) map[K]R
- func Reduce[K comparable, V, R any](f func(R, V) R, initial R) func(map[K]V) R
- func ReduceOrd[V, R any, K comparable](o ord.Ord[K]) func(func(R, V) R, R) func(map[K]V) R
- func ReduceOrdWithIndex[V, R any, K comparable](o ord.Ord[K]) func(func(K, R, V) R, R) func(map[K]V) R
- func ReduceRef[K comparable, V, R any](f func(R, *V) R, initial R) func(map[K]V) R
- func ReduceRefWithIndex[K comparable, V, R any](f func(K, R, *V) R, initial R) func(map[K]V) R
- func ReduceWithIndex[K comparable, V, R any](f func(K, R, V) R, initial R) func(map[K]V) R
- func Sequence[K comparable, A, HKTA, HKTAA, HKTRA any](fof func(map[K]A) HKTRA, ...) HKTRA
- func Singleton[K comparable, V any](k K, v V) map[K]V
- func Size[K comparable, V any](r map[K]V) int
- func ToArray[K comparable, V any](r map[K]V) []T.Tuple2[K, V]
- func ToEntries[K comparable, V any](r map[K]V) []T.Tuple2[K, V]
- func Traverse[K comparable, A, B, HKTB, HKTAB, HKTRB any](fof func(map[K]B) HKTRB, ...) func(map[K]A) HKTRB
- func TraverseWithIndex[K comparable, A, B, HKTB, HKTAB, HKTRB any](fof func(map[K]B) HKTRB, ...) func(map[K]A) HKTRB
- func Union[K comparable, V any](m Mg.Magma[V]) func(map[K]V) func(map[K]V) map[K]V
- func UnionFirstMonoid[K comparable, V any]() M.Monoid[map[K]V]
- func UnionFirstSemigroup[K comparable, V any]() S.Semigroup[map[K]V]
- func UnionLastMonoid[K comparable, V any]() M.Monoid[map[K]V]
- func UnionLastSemigroup[K comparable, V any]() S.Semigroup[map[K]V]
- func UnionMonoid[K comparable, V any](s S.Semigroup[V]) M.Monoid[map[K]V]
- func UnionSemigroup[K comparable, V any](s S.Semigroup[V]) S.Semigroup[map[K]V]
- func UpsertAt[K comparable, V any](k K, v V) func(map[K]V) map[K]V
- func Values[K comparable, V any](r map[K]V) []V
- func ValuesOrd[V any, K comparable](o ord.Ord[K]) func(r map[K]V) []V
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Ap ¶ added in v1.0.107
func Ap[A any, K comparable, B any](m Mo.Monoid[map[K]B]) func(fa map[K]A) func(map[K]func(A) B) map[K]B
func ApS ¶ added in v1.0.107
func ApS[S1, T any, K comparable, S2 any](m Mo.Monoid[map[K]S2]) func(setter func(T) func(S1) S2, fa map[K]T) func(map[K]S1) map[K]S2
ApS attaches a value to a context [S1] to produce a context [S2] by considering the context and the value concurrently
func Bind ¶ added in v1.0.107
func Bind[S1, T any, K comparable, S2 any](m Mo.Monoid[map[K]S2]) func(setter func(T) func(S1) S2, f func(S1) map[K]T) func(map[K]S1) map[K]S2
Bind attaches the result of a computation to a context [S1] to produce a context [S2]
func BindTo ¶ added in v1.0.107
func BindTo[S1, T any, K comparable](setter func(T) S1) func(map[K]T) map[K]S1
BindTo initializes a new state [S1] from a value [T]
func Chain ¶ added in v1.0.15
func Chain[V1 any, K comparable, V2 any](m Mo.Monoid[map[K]V2]) func(func(V1) map[K]V2) func(map[K]V1) map[K]V2
func ChainWithIndex ¶ added in v1.0.15
func ChainWithIndex[V1 any, K comparable, V2 any](m Mo.Monoid[map[K]V2]) func(func(K, V1) map[K]V2) func(map[K]V1) map[K]V2
func Clone ¶ added in v1.0.75
func Clone[K comparable, V any](f EM.Endomorphism[V]) EM.Endomorphism[map[K]V]
Clone creates a deep copy of the map using the provided endomorphism to clone the values
func Collect ¶
func Collect[K comparable, V, R any](f func(K, V) R) func(map[K]V) []R
Collect applies a collector function to the key value pairs in a map and returns the result as an array
func CollectOrd ¶ added in v1.0.58
func CollectOrd[V, R any, K comparable](o ord.Ord[K]) func(func(K, V) R) func(map[K]V) []R
CollectOrd applies a collector function to the key value pairs in a map and returns the result as an array
func Copy ¶ added in v1.0.75
func Copy[K comparable, V any](m map[K]V) map[K]V
Copy creates a shallow copy of the map
func DeleteAt ¶
func DeleteAt[K comparable, V any](k K) func(map[K]V) map[K]V
func Do ¶ added in v1.0.107
func Do[K comparable, S any]() map[K]S
Bind creates an empty context of type [S] to be used with the Bind operation
func Filter ¶
func Filter[K comparable, V any](f func(K) bool) func(map[K]V) map[K]V
Filter creates a new map with only the elements that match the predicate
func FilterChain ¶ added in v1.0.15
func FilterChain[V1 any, K comparable, V2 any](m Mo.Monoid[map[K]V2]) func(func(V1) O.Option[map[K]V2]) func(map[K]V1) map[K]V2
FilterChain creates a new map with only the elements for which the transformation function creates a Some
func FilterChainWithIndex ¶ added in v1.0.15
func FilterChainWithIndex[V1 any, K comparable, V2 any](m Mo.Monoid[map[K]V2]) func(func(K, V1) O.Option[map[K]V2]) func(map[K]V1) map[K]V2
FilterChainWithIndex creates a new map with only the elements for which the transformation function creates a Some
func FilterMap ¶
func FilterMap[K comparable, V1, V2 any](f func(V1) O.Option[V2]) func(map[K]V1) map[K]V2
FilterMap creates a new map with only the elements for which the transformation function creates a Some
func FilterMapWithIndex ¶
func FilterMapWithIndex[K comparable, V1, V2 any](f func(K, V1) O.Option[V2]) func(map[K]V1) map[K]V2
FilterMapWithIndex creates a new map with only the elements for which the transformation function creates a Some
func FilterWithIndex ¶
func FilterWithIndex[K comparable, V any](f func(K, V) bool) func(map[K]V) map[K]V
FilterWithIndex creates a new map with only the elements that match the predicate
func Flap ¶ added in v1.0.47
func Flap[B any, K comparable, A any](a A) func(map[K]func(A) B) map[K]B
func Flatten ¶ added in v1.0.15
func Flatten[K comparable, V any](m Mo.Monoid[map[K]V]) func(map[K]map[K]V) map[K]V
Flatten converts a nested map into a regular map
func Fold ¶ added in v1.0.16
func Fold[K comparable, A any](m Mo.Monoid[A]) func(map[K]A) A
Fold folds the record using the provided Monoid.
func FoldMap ¶ added in v1.0.16
func FoldMap[K comparable, A, B any](m Mo.Monoid[B]) func(func(A) B) func(map[K]A) B
FoldMap maps and folds a record. Map the record passing each value to the iterating function. Then fold the results using the provided Monoid.
Example ¶
src := map[string]string{ "a": "a", "b": "b", "c": "c", } fold := FoldMapOrd[string, string](S.Ord)(S.Monoid)(strings.ToUpper) fmt.Println(fold(src))
Output: ABC
func FoldMapOrd ¶ added in v1.0.16
func FoldMapOrd[A, B any, K comparable](o ord.Ord[K]) func(m Mo.Monoid[B]) func(func(A) B) func(map[K]A) B
FoldMap maps and folds a record. Map the record passing each value to the iterating function. Then fold the results using the provided Monoid and the items in the provided order
func FoldMapOrdWithIndex ¶ added in v1.0.16
func FoldMapOrdWithIndex[K comparable, A, B any](o ord.Ord[K]) func(m Mo.Monoid[B]) func(func(K, A) B) func(map[K]A) B
FoldMapWithIndex maps and folds a record. Map the record passing each value to the iterating function. Then fold the results using the provided Monoid and the items in the provided order
func FoldMapWithIndex ¶ added in v1.0.16
func FoldMapWithIndex[K comparable, A, B any](m Mo.Monoid[B]) func(func(K, A) B) func(map[K]A) B
FoldMapWithIndex maps and folds a record. Map the record passing each value to the iterating function. Then fold the results using the provided Monoid.
func FoldOrd ¶ added in v1.0.16
Fold folds the record using the provided Monoid with the items passed in the given order
func FromArray ¶ added in v1.0.98
FromArray converts from an array to a map Duplicate keys are resolved by the provided [Mg.Magma]
func FromArrayMap ¶ added in v1.0.98
func FromArrayMap[ A any, K comparable, V any](m Mg.Magma[V]) func(f func(A) T.Tuple2[K, V]) func(fa []A) map[K]V
FromArrayMap converts from an array to a map Duplicate keys are resolved by the provided [Mg.Magma]
func FromEntries ¶
func FromEntries[K comparable, V any](fa []T.Tuple2[K, V]) map[K]V
func FromFoldable ¶ added in v1.0.98
func FromFoldable[ HKTA any, FOLDABLE ~func(func(map[K]V, T.Tuple2[K, V]) map[K]V, map[K]V) func(HKTA) map[K]V, K comparable, V any](m Mg.Magma[V], red FOLDABLE) func(fa HKTA) map[K]V
FromFoldable converts from a reducer to a map Duplicate keys are resolved by the provided [Mg.Magma]
func FromFoldableMap ¶ added in v1.0.98
func FromFoldableMap[ FOLDABLE ~func(func(map[K]V, A) map[K]V, map[K]V) func(HKTA) map[K]V, A any, HKTA any, K comparable, V any](m Mg.Magma[V], red FOLDABLE) func(f func(A) T.Tuple2[K, V]) func(fa HKTA) map[K]V
FromFoldableMap converts from a reducer to a map Duplicate keys are resolved by the provided [Mg.Magma]
func Has ¶
func Has[K comparable, V any](k K, r map[K]V) bool
Has tests if a key is contained in a map
func IsNonEmpty ¶
func IsNonEmpty[K comparable, V any](r map[K]V) bool
IsNonEmpty tests if a map is not empty
func IsNonNil ¶
func IsNonNil[K comparable, V any](m map[K]V) bool
IsNonNil checks if the map is set to nil
func KeysOrd ¶ added in v1.0.16
func KeysOrd[V any, K comparable](o ord.Ord[K]) func(r map[K]V) []K
KeysOrd returns the keys in the map in their given order
func Let ¶ added in v1.0.107
func Let[S1, T any, K comparable, S2 any]( setter func(T) func(S1) S2, f func(S1) T, ) func(map[K]S1) map[K]S2
Let attaches the result of a computation to a context [S1] to produce a context [S2]
func LetTo ¶ added in v1.0.107
func LetTo[S1, T any, K comparable, S2 any]( setter func(T) func(S1) S2, b T, ) func(map[K]S1) map[K]S2
LetTo attaches the a value to a context [S1] to produce a context [S2]
func Lookup ¶
func Lookup[V any, K comparable](k K) func(map[K]V) O.Option[V]
Lookup returns the entry for a key in a map if it exists
func Map ¶
func Map[K comparable, V, R any](f func(V) R) func(map[K]V) map[K]R
func MapRef ¶
func MapRef[K comparable, V, R any](f func(*V) R) func(map[K]V) map[K]R
func MapRefWithIndex ¶
func MapRefWithIndex[K comparable, V, R any](f func(K, *V) R) func(map[K]V) map[K]R
func MapWithIndex ¶
func MapWithIndex[K comparable, V, R any](f func(K, V) R) func(map[K]V) map[K]R
func Merge ¶ added in v1.0.15
func Merge[K comparable, V any](right map[K]V) func(map[K]V) map[K]V
Merge combines two maps giving the values in the right one precedence. Also refer to MergeMonoid
func MergeMonoid ¶ added in v1.0.15
func MergeMonoid[K comparable, V any]() M.Monoid[map[K]V]
MergeMonoid computes the union of two maps of the same type giving the last map precedence
func MonadAp ¶ added in v1.0.107
func MonadAp[A any, K comparable, B any](m Mo.Monoid[map[K]B], fab map[K]func(A) B, fa map[K]A) map[K]B
func MonadChain ¶ added in v1.0.15
func MonadChain[V1 any, K comparable, V2 any](m Mo.Monoid[map[K]V2], r map[K]V1, f func(V1) map[K]V2) map[K]V2
func MonadChainWithIndex ¶ added in v1.0.15
func MonadChainWithIndex[V1 any, K comparable, V2 any](m Mo.Monoid[map[K]V2], r map[K]V1, f func(K, V1) map[K]V2) map[K]V2
func MonadFlap ¶ added in v1.0.47
func MonadFlap[B any, K comparable, A any](fab map[K]func(A) B, a A) map[K]B
func MonadLookup ¶ added in v1.0.24
func MonadLookup[V any, K comparable](m map[K]V, k K) O.Option[V]
MonadLookup returns the entry for a key in a map if it exists
func MonadMap ¶
func MonadMap[K comparable, V, R any](r map[K]V, f func(V) R) map[K]R
func MonadMapRef ¶
func MonadMapRef[K comparable, V, R any](r map[K]V, f func(*V) R) map[K]R
func MonadMapRefWithIndex ¶
func MonadMapRefWithIndex[K comparable, V, R any](r map[K]V, f func(K, *V) R) map[K]R
func MonadMapWithIndex ¶
func MonadMapWithIndex[K comparable, V, R any](r map[K]V, f func(K, V) R) map[K]R
func Reduce ¶
func Reduce[K comparable, V, R any](f func(R, V) R, initial R) func(map[K]V) R
func ReduceOrd ¶ added in v1.0.16
func ReduceOrd[V, R any, K comparable](o ord.Ord[K]) func(func(R, V) R, R) func(map[K]V) R
ReduceOrd reduces a map into a single value via a reducer function making sure that the keys are passed to the reducer in the specified order
func ReduceOrdWithIndex ¶ added in v1.0.16
func ReduceOrdWithIndex[V, R any, K comparable](o ord.Ord[K]) func(func(K, R, V) R, R) func(map[K]V) R
ReduceOrdWithIndex reduces a map into a single value via a reducer function making sure that the keys are passed to the reducer in the specified order
func ReduceRef ¶
func ReduceRef[K comparable, V, R any](f func(R, *V) R, initial R) func(map[K]V) R
func ReduceRefWithIndex ¶
func ReduceRefWithIndex[K comparable, V, R any](f func(K, R, *V) R, initial R) func(map[K]V) R
func ReduceWithIndex ¶
func ReduceWithIndex[K comparable, V, R any](f func(K, R, V) R, initial R) func(map[K]V) R
func Sequence ¶
func Sequence[K comparable, A, HKTA, HKTAA, HKTRA any]( fof func(map[K]A) HKTRA, fmap func(func(map[K]A) func(A) map[K]A) func(HKTRA) HKTAA, fap func(HKTA) func(HKTAA) HKTRA, ma map[K]HKTA) HKTRA
HKTA = HKT[A] HKTAA = HKT[func(A)map[K]A] HKTRA = HKT[map[K]A]
func Singleton ¶
func Singleton[K comparable, V any](k K, v V) map[K]V
Singleton creates a new map with a single entry
func Size ¶
func Size[K comparable, V any](r map[K]V) int
Size returns the number of elements in a map
func Traverse ¶
func Traverse[K comparable, A, B, HKTB, HKTAB, HKTRB any]( fof func(map[K]B) HKTRB, fmap func(func(map[K]B) func(B) map[K]B) func(HKTRB) HKTAB, fap func(HKTB) func(HKTAB) HKTRB, f func(A) HKTB) func(map[K]A) HKTRB
HKTA = HKT<A> HKTB = HKT<B> HKTAB = HKT<func(A)B> HKTRB = HKT<map[K]B>
func TraverseWithIndex ¶
func TraverseWithIndex[K comparable, A, B, HKTB, HKTAB, HKTRB any]( fof func(map[K]B) HKTRB, fmap func(func(map[K]B) func(B) map[K]B) func(HKTRB) HKTAB, fap func(HKTB) func(HKTAB) HKTRB, f func(K, A) HKTB) func(map[K]A) HKTRB
func UnionFirstMonoid ¶ added in v1.0.15
func UnionFirstMonoid[K comparable, V any]() M.Monoid[map[K]V]
UnionFirstMonoid computes the union of two maps of the same type giving the first map precedence
func UnionFirstSemigroup ¶ added in v1.0.15
func UnionFirstSemigroup[K comparable, V any]() S.Semigroup[map[K]V]
func UnionLastMonoid ¶ added in v1.0.15
func UnionLastMonoid[K comparable, V any]() M.Monoid[map[K]V]
UnionLastMonoid computes the union of two maps of the same type giving the last map precedence
func UnionLastSemigroup ¶ added in v1.0.15
func UnionLastSemigroup[K comparable, V any]() S.Semigroup[map[K]V]
func UnionMonoid ¶
UnionMonoid computes the union of two maps of the same type
func UnionSemigroup ¶
func UpsertAt ¶
func UpsertAt[K comparable, V any](k K, v V) func(map[K]V) map[K]V
func ValuesOrd ¶ added in v1.0.16
func ValuesOrd[V any, K comparable](o ord.Ord[K]) func(r map[K]V) []V
ValuesOrd returns the values in the map ordered by their keys in the given order
Example ¶
src := map[string]string{ "c": "a", "b": "b", "a": "c", } getValues := ValuesOrd[string](S.Ord) fmt.Println(getValues(src))
Output: [c b a]
Types ¶
This section is empty.