1
0
mirror of https://github.com/golang/go synced 2024-11-15 09:10:22 -07:00
go/doc/next/6-stdlib/3-iter.md
Jes Cok fd54936ea5 doc: simplify links for release notes
Change-Id: If9e3c5a58726ae3628d2e835d71f1a4708594c11
Reviewed-on: https://go-review.googlesource.com/c/go/+/586575
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Dmitri Shuralyov <dmitshur@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
2024-05-20 18:34:13 +00:00

1.4 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 m.
  • Keys returns an iterator over keys in m.
  • Values returns an iterator over values in m.
  • Insert adds the key-value pairs from seq to m.
  • Collect collects key-value pairs from seq into a new map and returns it.