maps

package
v0.37.0 Latest Latest
Warning

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

Go to latest
Published: Aug 22, 2023 License: Apache-2.0 Imports: 1 Imported by: 5

Documentation

Overview

Package maps provides handy functional programming -style functions that operate on map data types.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func All

func All[K comparable, V any](pairs map[K]V, f func(K, V) bool) bool

All returns true if all f(key, value) calls return true.

func Any

func Any[K comparable, V any](pairs map[K]V, f func(K, V) bool) bool

Any returns true if any f(key, value) call returns true.

func Count

func Count[K comparable, V any](pairs map[K]V, f func(K, V) bool) int

Count returns the count of items in the map for which `f(k, v)` returns true.

func HasKey

func HasKey[K comparable, V any](pairs map[K]V) func(k K) bool

HasKey returns a function that tests if a key exists in the map.

func Key

func Key[K comparable, V any](key K, value V) K

Key returns the key of a map key/value pair.

func Keys

func Keys[K comparable, V any](pairs map[K]V) []K

Keys returns the keys of a map.

func Map

func Map[K comparable, V any, T any](pairs map[K]V, f func(K, V) T) []T

Map maps the (k,v) pairs to a slice of values.

func ProductKeys

func ProductKeys[K Number, V any](pairs map[K]V) (ret K)

ProductKeys multiples the keys in a map together.

func ProductValues

func ProductValues[K comparable, V Number](pairs map[K]V) (ret V)

ProductValues multiples the values in a map together.

func Reduce

func Reduce[K comparable, V any, T any](pairs map[K]V, acc T, f func(K, V, T) T) T

Reduce reduces a map using an accumulator.

func ShallowCopy

func ShallowCopy[K comparable, V any](pairs map[K]V) map[K]V

ShallowCopy makes a shallow copy (top key/value pairs only) of the given map.

func SumKeys

func SumKeys[K Number, V any](pairs map[K]V) (ret K)

SumKeys sums up the keys in a map.

func SumValues

func SumValues[K comparable, V Number](pairs map[K]V) (ret V)

SumValues sums up the values in a map.

func Swap

func Swap[K comparable, V comparable](pairs map[K]V) map[V]K

Swap swaps the keys and values and returns a new map.

func Value

func Value[K any, V any](key K, value V) V

Value returns the value of a map key/value pair.

func ValueLen

func ValueLen[K any, T any](key K, value []T) int

ValueLen returns the length of the slice value of a map.

func Values

func Values[K comparable, V any](pairs map[K]V) []V

Values returns the values of a map.

Types

type Number

Number has the "+" operator.

Jump to

Keyboard shortcuts

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