Standard library / slices
slices.Backward()
Yields index and value pairs from the last element to the first. Expected stdout: '1 b\n0 a\n'.
Formal Syntax & Structure
go syntaxgo
func Backward[Slice ~[]E, E any](s Slice) iter.Seq2[int, E]Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| s | Slice | Input slice; may share its backing array. |
Return Value
iter.Seq2[int, E]
Yields index and value pairs from the last element to the first.
Working Example
Example Snippetgo
package main
import ( "fmt" "slices")
func main() { for i, v := range slices.Backward([]string{"a", "b"}) { fmt.Println(i, v) }}