G
- the success type of the OrB
- the failure type of the Orpublic final class Good<G,B> extends Object implements Or<G,B>, Serializable
Modifier and Type | Method and Description |
---|---|
Or<G,One<B>> |
accumulating()
|
Or<G,B> |
asOr()
Returns this Good with the type widened to Or.
|
<C> Or<G,C> |
badMap(Function<? super B,? extends C> mapper)
|
boolean |
contains(G good)
Returns true if this Or is a Good and its value is deeply equals to the given argument
according to
Objects.deepEquals(Object, Object) . |
boolean |
containsBad(B bad)
Returns true if this Or is a Bad and its value is deeply equals to the given argument
according to
Objects.deepEquals(Object, Object) . |
boolean |
equals(Object obj) |
boolean |
exists(Predicate<? super G> predicate)
|
Or<G,B> |
filter(Function<? super G,? extends Validation<? extends B>> validator)
Returns this
Or if either 1) it is a Bad or 2) it is a Good and applying
the validation function validation to this Good 's value returns Pass ; otherwise,
returns a new Bad containing the error value contained in the Fail resulting from
applying the validation function validation to this Good 's value. |
<H> Or<H,B> |
flatMap(Function<? super G,? extends Or<? extends H,? extends B>> func)
|
<V> V |
fold(Function<? super G,? extends V> good,
Function<? super B,? extends V> bad)
|
boolean |
forAll(Predicate<? super G> predicate)
|
void |
forEach(Consumer<? super G> action)
|
void |
forEach(Consumer<? super G> gc,
Consumer<? super B> bc)
A terminal operation to handle both success and failure cases.
|
G |
get()
|
B |
getBad()
|
G |
getOrElse(Function<? super B,? extends G> def)
|
G |
getOrElse(G alt)
|
int |
hashCode() |
boolean |
isBad()
|
boolean |
isGood()
|
<H> Or<H,B> |
map(Function<? super G,? extends H> mapper)
|
static <G,B> Good<G,B> |
of(G value) |
Or<G,B> |
orElse(Or<? extends G,? extends B> alt)
|
Or<G,B> |
orElse(Supplier<? extends Or<? extends G,? extends B>> alt)
|
Or<G,B> |
recover(Function<? super B,? extends G> func)
|
<C> Or<G,C> |
recoverWith(Function<? super B,? extends Or<? extends G,? extends C>> func)
|
Or<B,G> |
swap()
|
Either<B,G> |
toEither()
|
Optional<G> |
toJavaOptional()
|
Option<G> |
toOption()
|
String |
toString() |
<H,C> Or<H,C> |
transform(Function<? super G,? extends H> gf,
Function<? super B,? extends C> bf)
|
public static <G,B> Good<G,B> of(G value)
public Or<G,One<B>> accumulating()
Or
Or
to an Or
with the same Good
type and a Bad
type consisting of One
parameterized by this Or
's Bad
type.
For example, invoking the accumulating
method on an Or<Int,ErrorMessage>
would convert
it to an Or<Int,One<ErrorMessage>>
. This result type, because the Bad
type is an
Every
, can be used with the mechanisms provided in class Accumulation
to accumulate errors.
Note that if this Or
is already an accumulating Or
, the behavior of this
accumulating
method does not change. For example, if you invoke accumulating
on an
Or<Int,One<ErrorMessage>>
you will be rewarded with an
Or<Int,One<One<ErrorMessage>>>
.
Scalactic: def accumulating: Or[G, One[B]]
public Or<G,B> asOr()
Scalactic: def asOr: Or[G, B]
public <H> Or<H,B> map(Function<? super G,? extends H> mapper)
Or
public <C> Or<G,C> badMap(Function<? super B,? extends C> mapper)
Or
public boolean contains(G good)
Or
Objects.deepEquals(Object, Object)
.public boolean containsBad(B bad)
Or
Objects.deepEquals(Object, Object)
.containsBad
in interface Or<G,B>
bad
- the value to compare to this Or's value if it is a Badpublic boolean exists(Predicate<? super G> predicate)
Or
true
if this Or
is a Good
and the predicate p
returns
true when applied to this Good
's value.
Note: The exists
method will return the same result as Or.forAll(java.util.function.Predicate<? super G>)
if this Or
is a Good
, but the opposite result if this Or
is a Bad
.
Scalactic: def exists(p: (G) => Boolean): Boolean
public <H> Or<H,B> flatMap(Function<? super G,? extends Or<? extends H,? extends B>> func)
Or
public <V> V fold(Function<? super G,? extends V> good, Function<? super B,? extends V> bad)
Or
Or
into a value of type V
by applying the given gf
function if
this is a Good
else the given bf
function if this is a Bad
.
Scalactic: def fold[V](gf: (G) => V, bf: (B) => V): V
fold
in interface Or<G,B>
V
- the type of the fold's resultgood
- the function to apply to this Or
's Good
value, if it is a Good
bad
- the function to apply to this Or
's Bad
value, if it is a Bad
gf
or
bf
, to this Or
's valuepublic boolean forAll(Predicate<? super G> predicate)
Or
true
if either this Or
is a Bad
or if the predicate p
returns true
when applied to this Good
's value.
Note: This method will return the same result as Or.exists(java.util.function.Predicate<? super G>)
if this Or
is a Good
, but the opposite result if this Or
is a Bad
.
Scalactic: def forall(f: (G) => Boolean): Boolean
public G get()
Or
Or
's value if it is a Good
or throws NoSuchElementException
if
it is a Bad
.
Scalactic: def get: G
public G getOrElse(Function<? super B,? extends G> def)
Or
public Or<G,B> orElse(Supplier<? extends Or<? extends G,? extends B>> alt)
Or
public Or<G,B> recover(Function<? super B,? extends G> func)
Or
public <C> Or<G,C> recoverWith(Function<? super B,? extends Or<? extends G,? extends C>> func)
Or
public Optional<G> toJavaOptional()
Or
toJavaOptional
in interface Or<G,B>
Optional
public Either<B,G> toEither()
Or
Either
: a right Either
containing the Good
value, if this is a
Good
; a left Either
containing the Bad
value, if this is a Bad
.
Note that values effectively switch sides
when converting an Or
to an
Either
. If the type of the Or
on which you invoke this method is
Or<Int,ErrorMessage>
for example, the result will be an Either<ErrorMessage,Int>
.
The reason is that the convention for Either
is that left Either
is used for failure
values and right Either
is used for success
ones.
Scalactic: def toEither: Either[B, G]
public boolean isGood()
Or
public boolean isBad()
Or
public <H,C> Or<H,C> transform(Function<? super G,? extends H> gf, Function<? super B,? extends C> bf)
Or
Or
by applying the function gf
to this Or
's
Good
value if it is a Good
, or by applying bf
to this Or
's
Bad
value if it is a Bad
.
Scalactic: def transform[H, C](gf: (G) => Or[H, C], bf: (B) => Or[H, C]): Or[H, C]
transform
in interface Or<G,B>
H
- the type of the transformed Good
C
- the type of the transformed Bad
gf
- the function to apply to this Or
's Good
value, if it is a Good
bf
- the function to apply to this Or
's Bad
value, if it is a Bad
gf
or
bf
, to this Or
's valuepublic void forEach(Consumer<? super G> gc, Consumer<? super B> bc)
Or
public Or<G,B> filter(Function<? super G,? extends Validation<? extends B>> validator)
Or
Or
if either 1) it is a Bad
or 2) it is a Good
and applying
the validation function validation
to this Good
's value returns Pass
; otherwise,
returns a new Bad
containing the error value contained in the Fail
resulting from
applying the validation function validation
to this Good
's value.
For examples of filter
used in for
expressions, see the main documentation for interface
Validation
.
Scalactic: def filter[C >: B](f: (G) => Validation[C]): Or[G, C]
Copyright © 2016. All rights reserved.