Package e.java
Interface EOr<A>
- Type Parameters:
A
- Type of the value this EOr can contain
- All Known Implementing Classes:
EOr.Failure
,EOr.Success
public interface EOr<A>
A container that can either be a Failure containing an E or Success containing a value
- See Also:
-
Nested Class Summary
Modifier and TypeInterfaceDescriptionstatic final class
A failed EOrstatic final class
A successful EOr -
Field Summary
Modifier and TypeFieldDescriptionstatic final E
A default E to be used when condition does not hold while filtering an EOrA successful EOr of type Unit -
Method Summary
Modifier and TypeMethodDescriptiondefault <B> EOr<B>
Provides a next EOr if this one has a value, ignoring the valuestatic <A> EOr<A>
catching
(UnsafeSupplier<A> f, Function<Throwable, E> ifFailure) Constructs an EOr from a computation that can throwerror()
Filters this EOr by value in it, if it existsFilters this EOr by value in it, if it exists, using given functiondefault <B> EOr<B>
Computes a new EOr using value in this, if it exists, with given flat mapping functionflatMapError
(Function<E, EOr<A>> f) Computes a new EOr using E in this, if it exists, with given flat mapping functiondefault <B> B
Folds this into a single value, handling both E and value conversions with given functionsAlias of `onValue`static <A> EOr<A>
from
(A a) Constructs a successful EOr containing given valuestatic <A> EOr<A>
Constructs a failed EOr containing given Estatic <A> EOr<A>
fromNullable
(A a, Supplier<E> ifNull) Constructs an EOr from a nullable valuestatic <A> EOr<A>
fromOptional
(Optional<A> a, Supplier<E> ifEmpty) Constructs an EOr from an Optional valuedefault A
Gets the value in this or falls back to given default valuedefault boolean
hasError()
default boolean
hasValue()
default <B> EOr<B>
Converts value in this, if it exists, using given mapping function to make a new EOrConverts E in this, if it exists, using given mapping function to make a new EOrPerforms a side-effect using error in this, if it existsPerforms a side-effect using value in this, if it existsProvides an alternative EOr if this one has E, ignoring the Evalue()
-
Field Details
-
unit
A successful EOr of type Unit -
filteredError
A default E to be used when condition does not hold while filtering an EOr
-
-
Method Details
-
hasError
default boolean hasError()- Returns:
- Whether or not this contains an E
-
hasValue
default boolean hasValue()- Returns:
- Whether or not this contains a value
-
error
- Returns:
- E in this as an Optional
-
value
- Returns:
- Value in this as an Optional
-
map
Converts value in this, if it exists, using given mapping function to make a new EOr- Type Parameters:
B
- Type of the new value- Parameters:
f
- Mapping function- Returns:
- A new EOr containing either the new value or E in this one
-
flatMap
Computes a new EOr using value in this, if it exists, with given flat mapping function- Type Parameters:
B
- Type of the new value- Parameters:
f
- Flat mapping function- Returns:
- Computed EOr or a new EOr containing E in this one
-
mapError
Converts E in this, if it exists, using given mapping function to make a new EOr- Parameters:
f
- E mapping function- Returns:
- This EOr or a new EOr containing computed E if this one has E
-
flatMapError
Computes a new EOr using E in this, if it exists, with given flat mapping function- Parameters:
f
- E flat mapping function- Returns:
- This EOr or a computed EOr if this one has E
-
fold
Folds this into a single value, handling both E and value conversions with given functions- Type Parameters:
B
- Type of the desired result- Parameters:
ifFailure
- Conversion function for EifSuccess
- Conversion function for value- Returns:
- Converted result
-
getOrElse
Gets the value in this or falls back to given default value- Parameters:
alternative
- Default value to use in case this has E- Returns:
- Value in this or given default value
-
orElse
Provides an alternative EOr if this one has E, ignoring the E- Parameters:
alternative
- Alternative EOr in case this one has E- Returns:
- This EOr or alternative if this one has E
-
andThen
Provides a next EOr if this one has a value, ignoring the value- Type Parameters:
B
- Type of value in next EOr- Parameters:
next
- Next EOr in case this one has a value- Returns:
- Next EOr or a new EOr containing E in this one
-
onError
Performs a side-effect using error in this, if it exists- Parameters:
f
- Side-effecting function- Returns:
- This EOr for chaining
-
onValue
Performs a side-effect using value in this, if it exists- Parameters:
f
- Side-effecting function- Returns:
- This EOr for chaining
-
forEach
Alias of `onValue`- Returns:
- This EOr for chaining
- See Also:
-
filter
Filters this EOr by value in it, if it exists, using given function- Parameters:
condition
- Filtering functionfilteredError
- E conversion function- Returns:
- This EOr of a new EOr containing an E computed by given conversion function
-
filter
Filters this EOr by value in it, if it exists- Parameters:
condition
- Filtering function- Returns:
- This EOr of a new EOr containing an E
- See Also:
-
from
Constructs a failed EOr containing given E- Type Parameters:
A
- Type of value of resulting EOr- Parameters:
e
- An E- Returns:
- A new failed EOr containing given E
-
from
Constructs a successful EOr containing given value- Type Parameters:
A
- Type of value of resulting EOr- Parameters:
a
- A value- Returns:
- A new failed EOr containing given value
-
fromNullable
Constructs an EOr from a nullable value- Type Parameters:
A
- Type of value- Parameters:
a
- A nullable valueifNull
- An error to use in case value is null- Returns:
- An EOr containing either value or given E
-
fromOptional
Constructs an EOr from an Optional value- Type Parameters:
A
- Type of value- Parameters:
a
- An Optional valueifEmpty
- An error to use in case value is empty- Returns:
- An EOr containing either value or given E
-
catching
Constructs an EOr from a computation that can throw- Type Parameters:
A
- Type of value- Parameters:
f
- A computation that can throwifFailure
- An E conversion function- Returns:
- An EOr containing either computed value or an E computed by given function
-