Skip to content
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

Add methods to KiwiCollections to obtain first or last element of "sequenced" collections #813

Closed
sleberknight opened this issue Nov 29, 2022 · 0 comments · Fixed by #814
Assignees
Labels
new feature A new feature such as a new class, method, package, group of classes, etc.
Milestone

Comments

@sleberknight
Copy link
Member

This is inspired by JEP 431: Sequenced collections, and aims to add an easy way to obtain the first or last elements of "sequenced" collections. JEP 431 describes a sequenced collection as one with a "defined encounter order" and "Each such collection has a well-defined first element, second element, and so forth, up to the last element." That JEP aims (in JDK 21) to provide "uniform APIs for accessing its first and last elements, and for processing its elements in reverse order".

We are still supporting JDK 11, so won't have access to the JDK 21 APIs anytime soon. This task aims to provide a uniform API for accessing the first and last elements of "sequenced" collections, but does not provide any support for processing elements in reverse order.

The proposed methods are:

  • <T> T first(Collection<T> sequencedCollection)
  • <T> Optional<T> firstIfPresent(Collection<T> sequencedCollection)
  • <T> T last(Collection<T> sequencedCollection)
  • <T> Optional<T> lastIfPresent(Collection<T> sequencedCollection)

Other supporting methods will also be added for checking Collection arguments and checking whether a Collection is sequenced.

@sleberknight sleberknight added the new feature A new feature such as a new class, method, package, group of classes, etc. label Nov 29, 2022
@sleberknight sleberknight added this to the 2.4.0 milestone Nov 29, 2022
@sleberknight sleberknight self-assigned this Nov 29, 2022
sleberknight added a commit that referenced this issue Nov 29, 2022
Sequenced collections are defined by JEP 431, and are basically
collections that have a "defined encounter order", i.e. they have
first, second, third etc. elements up to a defined last element.

New public methods to access sequenced collections:
* firstIfPresent
* first
* lastIfPresent
* last

New public methods to check Collection arguments:
* checkNotEmptyCollection
* checkNonNullCollection

New public methods to check whether a Collection is sequenced:
* isSequenced

Closes #813
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new feature A new feature such as a new class, method, package, group of classes, etc.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant