-
Notifications
You must be signed in to change notification settings - Fork 2
/
maps.go2
43 lines (41 loc) · 1006 Bytes
/
maps.go2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// Functions that operate on maps
//
// Usage Notes
//
// • input data - input data to all functions is a map
// • arity - most functions have a arity of two wherein the function is prepared with all arguments in the first call and the input map is applied in the second call
package maps
// Values accepts a map and returns the values to each key as a slice
//
// Parameters
//
// • data: a map
//
// Return Value
//
// • result: slice of the values of the input map
//
func Values[TValue any, TKey comparable](data map[TKey]TValue) []TValue {
out := make([]TValue, 0)
for _, v := range data {
out = append(out, v)
}
return out
}
// Keys accepts a map and returns the keys to each value as a slice
//
// Parameters
//
// • data: a map
//
// Return Value
//
// • result: slice of the values of the input map
//
func Keys[TValue any, TKey comparable](data map[TKey]TValue) []TKey {
out := make([]TKey, 0)
for k := range data {
out = append(out, k)
}
return out
}