-
Notifications
You must be signed in to change notification settings - Fork 18.7k
Closed
Labels
LibraryProposalIssues describing a requested change to the Go standard library or x/ libraries, but not to a toolIssues describing a requested change to the Go standard library or x/ libraries, but not to a toolProposal
Milestone
Description
Proposal Details
I propose adding the following function:
package slices
// IndexAll returns the index of the first instance of sep in s, or -1 if sep is not present in s.
func IndexAll[S ~[]E, E comparable](s, sep S) int
Currently, slices.Index is too primitive and only does the trivial thing of computing whether a single element 2 is inside say {1, 1, 2, 3}.
On the other hand, bytes.Index is more powerful and allows us to search for {1, 2, 3} within {1, 1, 2, 3}.
The implementation of slices.IndexAll could simply be a version of bytes.Index converted to generics.
This would enable users to index []int, []image.Point the same way as []byte.
Metadata
Metadata
Assignees
Labels
LibraryProposalIssues describing a requested change to the Go standard library or x/ libraries, but not to a toolIssues describing a requested change to the Go standard library or x/ libraries, but not to a toolProposal