diff --git a/kala-base/src/main/java/kala/collection/base/OrderedTraversable.java b/kala-base/src/main/java/kala/collection/base/OrderedTraversable.java index 43098e22..77bce2ca 100644 --- a/kala-base/src/main/java/kala/collection/base/OrderedTraversable.java +++ b/kala-base/src/main/java/kala/collection/base/OrderedTraversable.java @@ -100,6 +100,11 @@ public interface OrderedTraversable extends Traversable { return Iterators.firstOption(reverseIterator(), predicate); } + @Override + default T getAny() { + return getFirst(); + } + default T getFirst() { return this.iterator().next(); } diff --git a/kala-base/src/main/java/kala/collection/base/Traversable.java b/kala-base/src/main/java/kala/collection/base/Traversable.java index 9e382bc6..af8911fb 100644 --- a/kala-base/src/main/java/kala/collection/base/Traversable.java +++ b/kala-base/src/main/java/kala/collection/base/Traversable.java @@ -110,6 +110,18 @@ default T elementAt(int index) { } } + default T getAny() { + return iterator().next(); + } + + default @Nullable T getAnyOrNull() { + return isNotEmpty() ? getAny() : null; + } + + default @NotNull Option getAnyOption() { + return isNotEmpty() ? Option.some(getAny()) : Option.none(); + } + //region Element Retrieval Operations default @NotNull Option find(@NotNull Predicate predicate) {