Add methods to KiwiCollections to obtain first or last element of "sequenced" collections #813
Labels
new feature
A new feature such as a new class, method, package, group of classes, etc.
Milestone
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 aCollection
is sequenced.The text was updated successfully, but these errors were encountered: