diff --git a/src/main/java/net/kemitix/conditional/Value.java b/src/main/java/net/kemitix/conditional/Value.java index f438e25..6345564 100644 --- a/src/main/java/net/kemitix/conditional/Value.java +++ b/src/main/java/net/kemitix/conditional/Value.java @@ -31,6 +31,41 @@ import java.util.function.Supplier; */ public interface Value { + /** + * Return one of two values depending on the value of a clause. + * + * @param clause The deciding clause + * @param trueSupplier The supplier to provide the value when the clause is true + * @param falseSupplier The supplier to provide the value when the clause is false + * @param The type of the value + * + * @return the value from either the trueSupplier or the falseSupplier + */ + static T where( + boolean clause, + Supplier trueSupplier, + Supplier falseSupplier + ) { + return Value.where(clause).then(trueSupplier) + .otherwise(falseSupplier); + } + + /** + * Return an Optional either containing a value, if the clause is true, or empty. + * + * @param clause The deciding clause + * @param trueSupplier The supplier to provide the value when the clause is true + * @param The type of the value + * + * @return an Optional either containing the value from the trueSupplier or empty + */ + static Optional where( + boolean clause, + Supplier trueSupplier + ) { + return Optional.ofNullable(Value.where(clause, trueSupplier, () -> null)); + } + /** * Create a new {@link ValueClause} for the clause. * @@ -56,22 +91,6 @@ public interface Value { return where(!clause); } - static T where( - boolean clause, - Supplier trueSupplier, - Supplier falseSupplier - ) { - return Value.where(clause).then(trueSupplier) - .otherwise(falseSupplier); - } - - static Optional where( - boolean clause, - Supplier trueSupplier - ) { - return Optional.ofNullable(Value.where(clause, trueSupplier, () -> null)); - } - /** * An intermediate state in determining the final {@link Value}. *