Skip to content

Commit

Permalink
Add kala.collection.MapLike::getOrThrow(K)
Browse files Browse the repository at this point in the history
  • Loading branch information
Glavo committed Jan 13, 2025
1 parent 99cf01d commit 2838abe
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@

### New features

* Add `kala.control.OptionContainer::getOrThrow()`
* Add `kala.collection.base.OrderedTraversable::mapIndexed(CollectionFactory<U, ?, R>, IndexedFunction<T, U>)`
* Add `kala.collection.base.OrderedTraversable::mapIndexedTo(G, IndexedFunction<T, U>)`
* Add `kala.collection.MapLike::getOrThrow(K)`
* Add `kala.collection.Set::added(E)`
* Add `kala.collection.Set::addedAll(E...)`
* Add `kala.collection.Set::addedAll(Iterable<E>)`
Expand Down
7 changes: 7 additions & 0 deletions kala-base/src/main/java/kala/control/OptionContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,13 @@ default <Ex extends Throwable> T getOrThrow(@NotNull Supplier<? extends Ex> supp
return get();
}

default T getOrThrow() {
if (isEmpty()) {
throw new NoSuchElementException();
}
return get();
}

default <U> U get(@NotNull Function<? super T, ? extends U> mapper) {
return mapper.apply(get());
}
Expand Down
4 changes: 4 additions & 0 deletions kala-collection/src/main/java/kala/collection/MapLike.java
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,10 @@ default <Ex extends Throwable> V getOrThrow(K key, @NotNull Supplier<? extends E
return getOption(key).getOrThrow(supplier);
}

default V getOrThrow(K key) {
return getOption(key).getOrThrow();
}

//region Element Conditions

default boolean contains(Tuple2<? extends K, ?> value) {
Expand Down

0 comments on commit 2838abe

Please sign in to comment.