public static class Xor.Secondary<ST,PT> extends java.lang.Object implements Xor<ST,PT>
Xor.Primary<ST,PT>, Xor.Secondary<ST,PT>
ApplicativeFunctor.Applicatives, ApplicativeFunctor.ApplyFunctions<T>
Value.ValueImpl<T>
Convertable.SupplierToConvertable<T>
Constructor and Description |
---|
Secondary() |
Modifier and Type | Method and Description |
---|---|
<T2,R> Xor<ST,R> |
combine(Value<? extends T2> app,
java.util.function.BiFunction<? super PT,? super T2,? extends R> fn)
Lazily combine this ApplicativeFunctor with the supplied value via the supplied BiFunction
Example
|
Xor<ST,PT> |
filter(java.util.function.Predicate<? super PT> test)
Keep only elements for which the supplied predicates hold
e.g.
|
<LT1,RT1> Xor<LT1,RT1> |
flatMap(java.util.function.Function<? super PT,? extends MonadicValue2<? extends LT1,? extends RT1>> mapper)
Perform a flattening transformation of this Monadicvalue2
|
PT |
get() |
boolean |
isPrimary() |
boolean |
isSecondary() |
<R> Xor<ST,R> |
map(java.util.function.Function<? super PT,? extends R> fn)
Transform this functor using the supplied transformation function
|
<R> Eval<R> |
matches(java.util.function.Function<Matchable.CheckValue1<ST,R>,Matchable.CheckValue1<ST,R>> secondary,
java.util.function.Function<Matchable.CheckValue1<PT,R>,Matchable.CheckValue1<PT,R>> primary,
java.util.function.Supplier<? extends R> otherwise)
Pattern match on the value/s inside this Xor.
|
java.lang.String |
mkString()
Returns the class name and the name of the subclass, if there is any value, the value is showed between square brackets.
|
Xor<ST,PT> |
peek(java.util.function.Consumer<? super PT> action)
Peek at the current value of this Functor, without transforming it
|
void |
peek(java.util.function.Consumer<? super ST> stAction,
java.util.function.Consumer<? super PT> ptAction) |
<LT1,RT1> Xor<LT1,RT1> |
secondaryFlatMap(java.util.function.Function<? super ST,? extends Xor<LT1,RT1>> mapper)
Perform a flatMap operation on the Secondary type
|
ST |
secondaryGet() |
<R> Xor<R,PT> |
secondaryMap(java.util.function.Function<? super ST,? extends R> fn)
Always map the Secondary type of this Xor if it is present using the provided transformation function
|
Xor<ST,PT> |
secondaryPeek(java.util.function.Consumer<? super ST> action)
Peek at the Secondary type value if present
|
java.util.Optional<ST> |
secondaryToOptional() |
Xor<ST,PT> |
secondaryToPrimayFlatMap(java.util.function.Function<? super ST,? extends Xor<ST,PT>> fn)
A flatMap operation that keeps the Secondary and Primary types the same
|
Xor<ST,PT> |
secondaryToPrimayMap(java.util.function.Function<? super ST,? extends PT> fn)
If this Xor contains the Secondary type, map it's value so that it contains the Primary type
|
ReactiveSeq<ST> |
secondaryToStream() |
Value<ST> |
secondaryValue() |
Xor<PT,ST> |
swap()
Swap types so operations directly affect the current (pre-swap) Secondary type
|
Ior<ST,PT> |
toIor()
Return an Ior that can be this object or a Ior.primary or Ior.secondary
|
Maybe<PT> |
toMaybe()
Returns a function result or a supplier result.
|
java.util.Optional<PT> |
toOptional() |
java.lang.String |
toString() |
ListX<ST> |
unapply() |
<R> R |
visit(java.util.function.Function<? super ST,? extends R> secondary,
java.util.function.Function<? super PT,? extends R> primary)
Visitor pattern for this Ior.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
accumulatePrimary, accumulatePrimary, accumulatePrimary, accumulateSecondary, accumulateSecondary, accumulateSecondary, anyM, bicast, bimap, bipeek, bitrampoline, cast, coflatMap, combine, combine, combineEager, combineToList, filterNot, flatMapIterable, flatMapPublisher, fromIterable, fromPublisher, isPresent, list, mapBoth, nest, notNull, ofType, patternMatch, primary, secondary, sequencePrimary, sequenceSecondary, toXor, toXor, trampoline, unit, zip, zip, zip, zip, zip, zip, zip
applyFunctions
collect, fold, fold, generate, iterate, iterator, mapReduce, newSubscriber, of, stream, subscribe, test, toDequeX, toEvalAlways, toEvalLater, toEvalNow, toFeatureToggle, toFutureStream, toFutureStream, toLazyImmutable, toList, toListX, toMutable, toPBagX, toPOrderedSetX, toPQueueX, toPSetX, toPStackX, toPVectorX, toQueueX, toSetX, toSimpleReact, toSimpleReact, toSortedSetX, toTry, toTry, toTry
endsWith, endsWithIterable, findAny, findFirst, firstValue, foldable, foldRight, foldRight, foldRight, foldRightMapToType, get, groupBy, join, join, join, mapReduce, print, print, printErr, printOut, reduce, reduce, reduce, reduce, reduce, reduce, reduce, schedule, scheduleFixedDelay, scheduleFixedRate, single, single, singleOptional, startsWith, startsWithIterable, toConcurrentLazyCollection, toConcurrentLazyStreamable, toLazyCollection, validate, xMatch
collect, fromSupplier, orElse, orElseGet, orElseThrow, toAtomicReference, toCompletableFuture, toCompletableFutureAsync, toCompletableFutureAsync, toFutureW, toFutureWAsync, toFutureWAsync, toOptionalAtomicReference, toStream, visit
public boolean isSecondary()
isSecondary
in interface Xor<ST,PT>
public boolean isPrimary()
public <R> Eval<R> matches(java.util.function.Function<Matchable.CheckValue1<ST,R>,Matchable.CheckValue1<ST,R>> secondary, java.util.function.Function<Matchable.CheckValue1<PT,R>,Matchable.CheckValue1<PT,R>> primary, java.util.function.Supplier<? extends R> otherwise)
Xor
import static com.aol.cyclops.control.Matchable.otherwise;
import static com.aol.cyclops.control.Matchable.then;
import static com.aol.cyclops.control.Matchable.when;
import static com.aol.cyclops.util.function.Predicates.instanceOf;
Xor.primary(10)
.matches(c->c.is(when("10"),then("hello")),
c->c.is(when(instanceOf(Integer.class)), then("error")),
otherwise("miss"))
.get()
//"error" Note the second case, 'primary' case is the one that matches
matches
in interface Xor<ST,PT>
secondary
- Pattern matching function executed if this Xor has the secondary typeprimary
- Pattern matching function executed if this Xor has the primary typeotherwise
- Supplier used to provide a value if the selecting pattern matching function fails to find a matchpublic Xor<ST,PT> secondaryToPrimayMap(java.util.function.Function<? super ST,? extends PT> fn)
Xor
secondaryToPrimayMap
in interface Xor<ST,PT>
fn
- Function to map secondary type to primarypublic <R> Xor<R,PT> secondaryMap(java.util.function.Function<? super ST,? extends R> fn)
Xor
secondaryMap
in interface Xor<ST,PT>
fn
- Transformation function for Secondary typespublic <R> Xor<ST,R> map(java.util.function.Function<? super PT,? extends R> fn)
Functor
of(1,2,3).map(i->i*2)
//[2,4,6]
map
in interface Xor<ST,PT>
map
in interface ConvertableFunctor<PT>
map
in interface Functor<PT>
map
in interface MonadicValue<PT>
map
in interface MonadicValue2<ST,PT>
fn
- Transformation functionpublic Xor<ST,PT> secondaryPeek(java.util.function.Consumer<? super ST> action)
Xor
secondaryPeek
in interface Xor<ST,PT>
action
- Consumer to peek at the Secondary type valuepublic Xor<ST,PT> peek(java.util.function.Consumer<? super PT> action)
Functor
of(1,2,3).map(System.out::println)
1
2
3
public Xor<ST,PT> filter(java.util.function.Predicate<? super PT> test)
Filterable
of(1,2,3).filter(i->i>2);
//[3]
public Xor<PT,ST> swap()
Xor
Xor.secondary("hello")
.map(v->v+" world")
//Xor.seconary["hello"]
Xor.secondary("hello")
.swap()
.map(v->v+" world")
.swap()
//Xor.seconary["hello world"]
public PT get()
public ST secondaryGet()
secondaryGet
in interface Xor<ST,PT>
public java.util.Optional<ST> secondaryToOptional()
secondaryToOptional
in interface Xor<ST,PT>
public ReactiveSeq<ST> secondaryToStream()
secondaryToStream
in interface Xor<ST,PT>
public <LT1,RT1> Xor<LT1,RT1> flatMap(java.util.function.Function<? super PT,? extends MonadicValue2<? extends LT1,? extends RT1>> mapper)
MonadicValue2
public <LT1,RT1> Xor<LT1,RT1> secondaryFlatMap(java.util.function.Function<? super ST,? extends Xor<LT1,RT1>> mapper)
Xor
secondaryFlatMap
in interface Xor<ST,PT>
mapper
- Flattening transformation functionpublic Xor<ST,PT> secondaryToPrimayFlatMap(java.util.function.Function<? super ST,? extends Xor<ST,PT>> fn)
Xor
secondaryToPrimayFlatMap
in interface Xor<ST,PT>
fn
- Transformation functionpublic void peek(java.util.function.Consumer<? super ST> stAction, java.util.function.Consumer<? super PT> ptAction)
public <R> R visit(java.util.function.Function<? super ST,? extends R> secondary, java.util.function.Function<? super PT,? extends R> primary)
Xor
Xor.primary(10)
.visit(secondary->"no", primary->"yes")
//Xor["yes"]
Xor.secondary(90)
.visit(secondary->"no", primary->"yes")
//Xor["no"]
public Maybe<PT> toMaybe()
Value
public java.util.Optional<PT> toOptional()
toOptional
in interface Xor<ST,PT>
toOptional
in interface Convertable<PT>
public Value<ST> secondaryValue()
secondaryValue
in interface Xor<ST,PT>
public java.lang.String toString()
toString
in class java.lang.Object
public java.lang.String mkString()
Value
public Ior<ST,PT> toIor()
Value
public <T2,R> Xor<ST,R> combine(Value<? extends T2> app, java.util.function.BiFunction<? super PT,? super T2,? extends R> fn)
Combiner
Maybe<Integer> some = Maybe.just(10);
just.combine(Eval.now(20), this::add);
//Some[30]
Maybe<Integer> none = Maybe.none();
none.combine(Eval.now(20), this::add);
//None