Skip to content

Commit

Permalink
Add getOpt() method.
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasMikula committed Jun 17, 2014
1 parent 4db1e05 commit 5460fb9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ interface MonadicObservableValue<T> extends ObservableValue<T> {
void ifPresent(Consumer<? super T> f);
T getOrThrow();
T getOrElse(T other);
Optional<T> getOpt();
MonadicBinding<T> orElse(T other);
MonadicBinding<T> orElse(ObservableValue<T> other);
MonadicBinding<T> filter(Predicate<? super T> p);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.fxmisc.easybind.monadic;

import java.util.NoSuchElementException;
import java.util.Optional;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Predicate;
Expand Down Expand Up @@ -78,6 +79,15 @@ default T getOrElse(T other) {
}
}

/**
* Returns an {@code Optional} describing the value currently held by this
* ObservableValue, or and empty {@code Optional} if this ObservableValue
* is empty.
*/
default Optional<T> getOpt() {
return Optional.ofNullable(getValue());
}

/**
* Returns a new ObservableValue that holds the value held by this
* ObservableValue, or {@code other} when this ObservableValue is empty.
Expand Down

0 comments on commit 5460fb9

Please sign in to comment.