maps

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: May 11, 2022 License: MIT Imports: 0 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func ToSlice

func ToSlice[M ~map[K]V, K comparable, V, R any](items M, f func(K, V) R) []R

ToSlice applies the function to each element of the input map, and returns an array of the results.

Example
nums := map[string]int{
	"one":   1,
	"two":   2,
	"three": 3,
}
fn := func(k string, v int) string {
	return fmt.Sprintf("%d in text is %s", v, k)
}
results := ToSlice(nums, fn)

sort.Strings(results) // order is not guaranteed for map keys
fmt.Println(results)
Output:

[1 in text is one 2 in text is two 3 in text is three]

func ToValues

func ToValues[In any, Key comparable](arr map[Key]In) []In

ToValues returns an array of just the values of the input Map.

Example
nums := map[string]int{
	"one":   1,
	"two":   2,
	"three": 3,
}
results := ToValues(nums)

sort.Ints(results) // order is not guaranteed for map keys
fmt.Println(results)
Output:

[1 2 3]

Types

This section is empty.

Jump to

Keyboard shortcuts

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