Package com.terheyden.value
Class ValueStack
java.lang.Object
com.terheyden.value.ValueStack
A value stack can collect and combine multiple values in a functional way.
Value objects are identical to
Optional, with some added features to support combining values.
New methods added (besides the ones from Optional):
Value1(Optional)— avoids having to unwrap Optionalsof(Optional)— support for conversion between Values and OptionalsValue1.andOf(Object)— multi-value support; adds a new value to the stackValue1.andOf(Optional)— multi-value support; adds a new value to the stackValue1.andOf(CheckedFunction1)— multi-value support; adds a new value to the stackValue1.andOfNullable(Object)— multi-value support; adds a new value to the stackValue1.andOfNullable(CheckedFunction1)— multi-value support; adds a new value to the stackValue1.or(Optional)— replace the last value, if empty, with the given optionalValue1.or(Value1)— replace the last empty value with the given replacementValue1.or(CheckedFunction0)— use all values to generate a new value to replace the empty oneValue1.or(Object)— a chainable version oforElse(), uses the given value to replace emptyValue1.ifEmpty(CheckedRunnable)— to complement ifPresent()Value2.ifAllPresent(CheckedConsumer2)— use all values without needing to reduceValue1.toOptional()— support conversion between Values and OptionalsValue2.reduceAll(CheckedFunction2)— combine all stack values into a resultValue2.flatReduceAll(CheckedFunction2)— combine all stack values into a result Value
Changes to Optional methods (all non-breaking):
- All functional interfaces now handle checked exceptions (uses Vavr library)
Value1.ifPresent(CheckedConsumer)— now returns self for chainingValue1.ifPresentOrElse(CheckedConsumer, CheckedRunnable)— now returns self for chaining
-
Method Summary
Modifier and TypeMethodDescriptionstatic <A> Value1<A>of(A value) Create a new value stack with the given initial value.static <A,B> Value2<A, B> of(A value1, B value2) Create a new value stack with the given initial values.static <A> Value1<A>Create a new value stack with the given initial value.static <A,B> Value2<A, B> Create a new value stack with the given initial values.static <A> Value1<A>ofNullable(A value) Create a new value stack with the given initial value.static <A,B> Value2<A, B> ofNullable(A value1, B value2) Create a new value stack with the given initial values.
-
Method Details
-
ofNullable
Create a new value stack with the given initial value. Value objects work exactly likeOptional, but can be combined. -
ofNullable
Create a new value stack with the given initial values. Value objects work exactly likeOptional, but can be combined. -
of
Create a new value stack with the given initial value. Value objects work exactly likeOptional, but can be combined. -
of
Create a new value stack with the given initial values. Value objects work exactly likeOptional, but can be combined. -
of
Create a new value stack with the given initial value. Value objects work exactly likeOptional, but can be combined. -
of
public static <A,B> Value2<A,B> of(Optional<? extends A> optValue1, Optional<? extends B> optValue2) Create a new value stack with the given initial values. Value objects work exactly likeOptional, but can be combined.
-