maps

package
v2.0.0-alpha.3 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2024 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package maps provides early implementations of map-related functions available in Go 1.23+.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func All

func All[Map ~map[K]V, K comparable, V any](m Map) iter.Seq2[K, V]

All returns an iterator over key-value pairs from m. The iteration order is not specified and is not guaranteed to be the same from one call to the next.

Example
package main

import (
	"fmt"

	"github.com/BooleanCat/go-functional/v2/future/maps"
)

func main() {
	for key, value := range maps.All(map[int]string{1: "one", 2: "two", 3: "three"}) {
		fmt.Println(key, value)
	}
}

func Collect

func Collect[K comparable, V any](seq iter.Seq2[K, V]) map[K]V

Collect collects key-value pairs from seq into a new map and returns it.

Example
package main

import (
	"fmt"

	"github.com/BooleanCat/go-functional/v2/future/maps"
)

func main() {
	numbers := maps.Collect(maps.All(map[int]string{1: "one", 2: "two"}))

	fmt.Println(numbers[0])
	fmt.Println(numbers[1])
	// Output
	// one
	// two
}

Types

This section is empty.

Jump to

Keyboard shortcuts

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