Logo

Programming-Idioms

History of Idiom 222 > diff from v36 to v37

Edit summary for version 37 by programming-idioms.org:
[Go] Go 1.21

Version 36

2023-02-03, 08:20:16

Version 37

2023-08-17, 12:31:34

Idiom #222 Find the first index of an element in list

Set i to the first index in list items at which the element x can be found, or -1 if items does not contain x.

Idiom #222 Find the first index of an element in list

Set i to the first index in list items at which the element x can be found, or -1 if items does not contain x.

Variables
i,x,items
Variables
i,x,items
Extra Keywords
position
Extra Keywords
position
Imports
import "golang.org/x/exp/slices"
Imports
import "slices"
Code
i := slices.Index(items, x)
Code
i := slices.Index(items, x)
Comments bubble
This generic func slices.Index works for all slice types
Comments bubble
This generic func slices.Index works for all slice types
Doc URL
https://pkg.go.dev/golang.org/x/exp/slices#Index
Doc URL
https://pkg.go.dev/slices#Index
Demo URL
https://go.dev/play/p/EBF1O2eofa1
Demo URL
https://go.dev/play/p/yY5VRYPSdRb