Skip to content

Commit

Permalink
More checked/unchecked methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Glavo committed Dec 13, 2024
1 parent a287d50 commit 8802be6
Showing 1 changed file with 73 additions and 0 deletions.
73 changes: 73 additions & 0 deletions kala-base/src/main/java/kala/collection/base/Traversable.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import kala.tuple.Tuple2;
import kala.value.primitive.IntVar;
import org.intellij.lang.annotations.Flow;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
Expand Down Expand Up @@ -182,6 +183,16 @@ default boolean anyMatch(@NotNull Predicate<? super T> predicate) {
return Iterators.anyMatch(iterator(), predicate);
}

@ApiStatus.NonExtendable
default <Ex extends Throwable> boolean anyMatchChecked(@NotNull CheckedPredicate<? super T, ? extends Ex> predicate) throws Ex {
return anyMatch(predicate);
}

@ApiStatus.NonExtendable
default boolean anyMatchUnchecked(@NotNull CheckedPredicate<? super T, ?> predicate) {
return anyMatch(predicate);
}

/**
* Tests whether all elements of this {@code Traversable} match the {@code predicate}.
*
Expand All @@ -192,6 +203,16 @@ default boolean allMatch(@NotNull Predicate<? super T> predicate) {
return Iterators.allMatch(iterator(), predicate);
}

@ApiStatus.NonExtendable
default <Ex extends Throwable> boolean allMatchChecked(@NotNull CheckedPredicate<? super T, ? extends Ex> predicate) throws Ex {
return allMatch(predicate);
}

@ApiStatus.NonExtendable
default boolean allMatchUnchecked(@NotNull CheckedPredicate<? super T, ?> predicate) {
return allMatch(predicate);
}

/**
* Tests whether none elements of this {@code Traversable} match the {@code predicate}.
*
Expand All @@ -202,27 +223,79 @@ default boolean noneMatch(@NotNull Predicate<? super T> predicate) {
return Iterators.noneMatch(iterator(), predicate);
}

@ApiStatus.NonExtendable
default <Ex extends Throwable> boolean noneMatchChecked(@NotNull CheckedPredicate<? super T, ? extends Ex> predicate) throws Ex {
return noneMatch(predicate);
}

@ApiStatus.NonExtendable
default boolean noneMatchUnchecked(@NotNull CheckedPredicate<? super T, ?> predicate) {
return noneMatch(predicate);
}

/**
* Equivalent to {@code this.zip(other).anyMatch(it -> predicate.test(it._1, it._2))}
*/
default <U> boolean anyMatchWith(@NotNull Iterable<? extends U> other, @NotNull BiPredicate<? super T, ? super U> predicate) {
return Iterators.anyMatchWith(iterator(), other.iterator(), predicate);
}

@ApiStatus.NonExtendable
default <U, Ex extends Throwable> boolean anyMatchWithChecked(
@NotNull Iterable<? extends U> other,
@NotNull CheckedBiPredicate<? super T, ? super U, ? extends Ex> predicate) throws Ex {
return anyMatchWith(other, predicate);
}

@ApiStatus.NonExtendable
default <U> boolean anyMatchWithUnchecked(
@NotNull Iterable<? extends U> other,
@NotNull CheckedBiPredicate<? super T, ? super U, ?> predicate) {
return anyMatchWith(other, predicate);
}

/**
* Equivalent to {@code this.zip(other).allMatch(it -> predicate.test(it._1, it._2))}
*/
default <U> boolean allMatchWith(@NotNull Iterable<? extends U> other, @NotNull BiPredicate<? super T, ? super U> predicate) {
return Iterators.allMatchWith(iterator(), other.iterator(), predicate);
}

@ApiStatus.NonExtendable
default <U, Ex extends Throwable> boolean allMatchWithChecked(
@NotNull Iterable<? extends U> other,
@NotNull CheckedBiPredicate<? super T, ? super U, ? extends Ex> predicate) throws Ex {
return allMatchWith(other, predicate);
}

@ApiStatus.NonExtendable
default <U> boolean allMatchWithUnchecked(
@NotNull Iterable<? extends U> other,
@NotNull CheckedBiPredicate<? super T, ? super U, ?> predicate) {
return allMatchWith(other, predicate);
}

/**
* Equivalent to {@code this.zip(other).noneMatch(it -> predicate.test(it._1, it._2))}
*/
default <U> boolean noneMatchWith(@NotNull Iterable<? extends U> other, @NotNull BiPredicate<? super T, ? super U> predicate) {
return Iterators.noneMatchWith(iterator(), other.iterator(), predicate);
}

@ApiStatus.NonExtendable
default <U, Ex extends Throwable> boolean noneMatchWithChecked(
@NotNull Iterable<? extends U> other,
@NotNull CheckedBiPredicate<? super T, ? super U, ? extends Ex> predicate) throws Ex {
return noneMatchWith(other, predicate);
}

@ApiStatus.NonExtendable
default <U> boolean noneMatchWithUnchecked(
@NotNull Iterable<? extends U> other,
@NotNull CheckedBiPredicate<? super T, ? super U, ?> predicate) {
return noneMatchWith(other, predicate);
}

//endregion

@DelegateBy("filterTo(Growable<T>, Predicate<T>)")
Expand Down

0 comments on commit 8802be6

Please sign in to comment.