-
Notifications
You must be signed in to change notification settings - Fork 18.3k
Open
Description
I propose adding the following function to slices:
// Shift removes the first element from s, returning false if the slice is empty.
func Shift[S ~[]E, E any](s S) (first E, rest S, ok bool) {
if len(s) == 0 {
rest = s
} else {
first, rest, ok = s[0], s[1:], true
}
return
}
Like #64095, this is useful for parsing stuff.
Update: I think this is better without the ok
return value.
apparentlymart, djordje200179, chad-bekmezian-snap and y1yang0seankhliao, ivila and adonovan
Metadata
Metadata
Assignees
Labels
Type
Projects
Status
Incoming