go/doc/next/6-stdlib/3-iter.md
Cherry Mui 3622ad9705 doc/next: reword map iterator function notes
The notes don't define identifiers m and seq. Describe in words
instead.

While here, rename 3-structs.md to 4-structs.md.

For #65614.

Change-Id: I6690f552903d1870c70e28673c87ac84b7c5c041
Reviewed-on: https://go-review.googlesource.com/c/go/+/592195
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-06-12 18:30:46 +00:00

1.5 KiB

Iterators

The new [iter] package provides the basic definitions for working with user-defined iterators.

The [slices] package adds several functions that work with iterators:

  • All returns an iterator over slice indexes and values.
  • Values returns an iterator over slice elements.
  • Backward returns an iterator that loops over a slice backward.
  • Collect collects values from an iterator into a new slice.
  • AppendSeq appends values from an iterator to an existing slice.
  • Sorted collects values from an iterator into a new slice, and then sorts the slice.
  • SortedFunc is like Sorted but with a comparison function.
  • SortedStableFunc is like SortFunc but uses a stable sort algorithm.
  • Chunk returns an iterator over consecutive sub-slices of up to n elements of a slice.

The [maps] package adds several functions that work with iterators:

  • All returns an iterator over key-value pairs from a map.
  • Keys returns an iterator over keys in a map.
  • Values returns an iterator over values in a map.
  • Insert adds the key-value pairs from an iterator to an existing map.
  • Collect collects key-value pairs from an iterator into a new map and returns it.