-
Notifications
You must be signed in to change notification settings - Fork 10.9k
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
Provide an Iterables.tail() method #1906
Comments
AFAIK, most languages' concept associated with the word "tail" would not be On Mon Dec 08 2014 at 5:38:56 PM Michael Diamond notifications@github.com
|
@lowasser: Hmm, any examples? We use |
Hmmm. I was thinking about Haskell, where "tail" refers to a list without I do think that e.g. FluentIterable.last(5) would be fairly unambiguous, On Mon Dec 08 2014 at 5:52:40 PM Colin Decker notifications@github.com
|
Few thoughts:
|
I understand that this issue is about a new method for getting the tailing/last/trailing N elements, but if anyone hits this page while searching for a method to find THE last element, as I just have, then FYI com.google.common.collect.Iterables's T getLast(Iterable iterable) is what you are looking for (it's optimized for List). |
Note that our current offering here is EvictingQueue.
|
Just to mention that a302923 makes |
I have a need to select the most recent
n
elements from a list that I know is ordered; for instance, to display data from the last ten years, in a (potentially long) list of data ordered by year.For existing Lists it's tedious but not complicated to write out:
though I'd argue the cleanliness of a simple
.tail()
method is still a nice win over the above. More valuable however is providing support for arbitrary Iterables, in order to avoid creating a copy of the whole data stream simply to take a small sublist. I imagine many users (myself included) simply absorb the cost of the full copy rather than take the time to implement a circular buffer or similar memory-efficient solution.The text was updated successfully, but these errors were encountered: