Skip to content

proposal: slices.Last: return the last element of a non-empty slice #69005

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
adonovan opened this issue Aug 21, 2024 · 4 comments
Closed

proposal: slices.Last: return the last element of a non-empty slice #69005

adonovan opened this issue Aug 21, 2024 · 4 comments

Comments

@adonovan
Copy link
Member

adonovan commented Aug 21, 2024

A common operation is to access the last element of a slice. When the slice is not in a variable this can be cumbersome because of the need to repeat the argument.

We propose to add the Last function to the slices package.

package slices

// Last returns the last element of a non-empty slice.
func Last[S ~[]E, E any](slice S) E {
	return slice[len(slice)-1]
}
@gopherbot gopherbot added this to the Proposal milestone Aug 21, 2024
@adonovan adonovan moved this to Incoming in Proposals Aug 21, 2024
@gabyhelp
Copy link

@adonovan
Copy link
Member Author

Hmm, Gaby turned up something my search through (open) proposals did not:

It appears we have been here before and decided against it.

@zigo101
Copy link

zigo101 commented Aug 22, 2024

also see: #25594

@seankhliao
Copy link
Member

Given that it was only recently declined, let's close as

Duplicate of #53510

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants