You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
With the addition of SequencedCollection in Java 21, List supports methods getFirst() and getLast().
Similarly, I think 'ListOperations' in 'RedisTemplate' could be improved by introducing a method like getFirst(key) instead of index(key, 0).
How about add methods like the code I wrote below?
/** * Returns the first element from list at {@code key}. * * @implSpec * The implementation in this interface returns the result of calling {@code index(key, 0)}. * * @param key must not be {@literal null}. * @return {@literal null} when used in pipeline / transaction. */@NullabledefaultVgetFirst(Kkey) {
returnindex(key, 0);
}
/** * Returns the last element from list at {@code key}. * * @implSpec * If the result of calling {@code size(key)} is not null, The implementation in this interface returns the * result of calling {@code index(key, size - 1)}. Otherwise, it returns null. * * @param key must not be {@literal null}. * @return {@literal null} when used in pipeline / transaction. */@NullabledefaultVgetLast(Kkey) {
Longsize = size(key);
returnsize != null ? index(key, size - 1) : null;
}
The text was updated successfully, but these errors were encountered:
Generally, we keep our …Operations interfaces aligned with the corresponding Redis commands. Adding these convenience methods would be neat. Feel free to submit a pull request if you like.
Add getFirst/getLast to Reactive and Bound Operations.
Simplify getLast implementation.
Reorder methods, tweak Javadoc, add since tags.
Original pull request: #2966
See #2937
With the addition of
SequencedCollection
in Java 21,List
supports methodsgetFirst()
andgetLast()
.Similarly, I think 'ListOperations' in 'RedisTemplate' could be improved by introducing a method like
getFirst(key)
instead ofindex(key, 0)
.How about add methods like the code I wrote below?
The text was updated successfully, but these errors were encountered: