Skip to content

maps: Clarify iteration order of Keys & Values and that Insert overwrites existing keys #67537

Closed
@magical

Description

@magical

These functions were added in 2b0f2f8 with minimal documentation.

// Keys returns an iterator over keys in m.
func Keys[Map ~map[K]V, K comparable, V any](m Map) iter.Seq[K] {
	...
}

// Values returns an iterator over values in m.
func Values[Map ~map[K]V, K comparable, V any](m Map) iter.Seq[V] {
	...
}

// Insert adds the key-value pairs from seq to m.
func Insert[Map ~map[K]V, K comparable, V any](m Map, seq iter.Seq2[K, V]) {
	...
}

The doc comments should be updated to specify the iteration order of Keys and Values, and the behaviour of Insert when duplicate keys are inserted, per discussion on #61900 and in particular rsc's comment:

Happy to update docs to say that iteration order is undefined (different each time) and Insert does overwrite keys.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DocumentationIssues describing a change to documentation.FrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.compiler/runtimeIssues related to the Go compiler and/or runtime.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions