ST
- Secondary typePT
- Primary typepublic interface Xor<ST,PT> extends java.util.function.Supplier<PT>, Value<PT>, Functor<PT>, Filterable<PT>, Applicativable<PT>
Xor.primary("hello").map(v->v+" world")
//Xor.primary["hello world"]
Values can be accumulated via
Xor.accumulateSecondary(ListX.of(Xor.secondary("failed1"),
Xor.secondary("failed2"),
Xor.primary("success")),
Semigroups.stringConcat)
//failed1failed2
Xor<String,String> fail1 = Xor.secondary("failed1");
fail1.swap().ap((a,b)->a+b)
.ap(Xor.secondary("failed2").swap())
.ap(Xor.<String,String>primary("success").swap())
//failed1failed2
Modifier and Type | Interface and Description |
---|---|
static class |
Xor.Primary<ST,PT> |
static class |
Xor.Secondary<ST,PT> |
Applicativable.Applicatives, Applicativable.SemigroupApplyer<T>
Value.ValueImpl<T>
Matchable.AsMatchable, Matchable.AutoCloseableMatchableIterable<TYPE>, Matchable.CheckValue1<T,R>, Matchable.CheckValue2<T1,T2,R>, Matchable.CheckValue3<T1,T2,T3,R>, Matchable.CheckValue4<T1,T2,T3,T4,R>, Matchable.CheckValue5<T1,T2,T3,T4,T5,R>, Matchable.CheckValueOpt<T,R>, Matchable.CheckValues<T,R>, Matchable.MatchableIterable<TYPE>, Matchable.MatchableObject<TYPE>, Matchable.MatchableOptional<T>, Matchable.MatchSelf<TYPE>, Matchable.MTuple1<T1>, Matchable.MTuple2<T1,T2>, Matchable.MTuple3<T1,T2,T3>, Matchable.MTuple4<T1,T2,T3,T4>, Matchable.MTuple5<T1,T2,T3,T4,T5>, Matchable.MXor<T1,T2>, Matchable.ValueAndOptionalMatcher<T>
Convertable.SupplierToConvertable<T>
Modifier and Type | Method and Description |
---|---|
static <ST,PT,R> Xor<?,R> |
accumulatePrimary(CollectionX<Xor<ST,PT>> xors,
java.util.function.Function<? super PT,R> mapper,
Semigroup<R> reducer) |
static <ST,PT,R> Xor<?,R> |
accumulatePrimary(CollectionX<Xor<ST,PT>> xors,
Reducer<R> reducer) |
static <ST,PT> Xor<?,PT> |
accumulatePrimary(CollectionX<Xor<ST,PT>> xors,
Semigroup<PT> reducer) |
static <ST,PT,R> Xor<?,R> |
accumulateSecondary(CollectionX<Xor<ST,PT>> xors,
java.util.function.Function<? super ST,R> mapper,
Semigroup<R> reducer) |
static <ST,PT,R> Xor<?,R> |
accumulateSecondary(CollectionX<Xor<ST,PT>> xors,
Reducer<R> reducer) |
static <ST,PT> Xor<?,ST> |
accumulateSecondary(CollectionX<Xor<ST,PT>> xors,
Semigroup<ST> reducer)
Xor.accumulateSecondary(ListX.of(Xor.secondary("failed1"),
Xor.secondary("failed2"),
Xor.primary("success")),
Semigroups.stringConcat)
//Xors.Primary[failed1failed2]
|
default AnyMValue<PT> |
anyM() |
default <U> Xor<ST,U> |
cast(java.lang.Class<U> type)
Cast all elements in a stream to a given type, possibly throwing a
ClassCastException . |
Xor<ST,PT> |
filter(java.util.function.Predicate<? super PT> test) |
default Xor<ST,PT> |
filterNot(java.util.function.Predicate<? super PT> fn) |
<LT1,RT1> Xor<LT1,RT1> |
flatMap(java.util.function.Function<? super PT,? extends Xor<LT1,RT1>> mapper) |
PT |
get() |
boolean |
isPrimary() |
boolean |
isSecondary() |
<R> Xor<ST,R> |
map(java.util.function.Function<? super PT,? extends R> fn) |
<R> Eval<R> |
matches(java.util.function.Function<Matchable.CheckValue1<ST,R>,Matchable.CheckValue1<ST,R>> fn1,
java.util.function.Function<Matchable.CheckValue1<PT,R>,Matchable.CheckValue1<PT,R>> fn2,
java.util.function.Supplier<? extends R> otherwise) |
default Xor<ST,PT> |
notNull() |
default <U> Xor<ST,U> |
ofType(java.lang.Class<U> type)
Keep only those elements in a stream that are of a given type.
|
default <R> Xor<ST,R> |
patternMatch(java.util.function.Function<Matchable.CheckValues<PT,R>,Matchable.CheckValues<PT,R>> case1,
java.util.function.Supplier<? extends R> otherwise)
Transform the elements of this Stream with a Pattern Matching case and default value
|
Xor<ST,PT> |
peek(java.util.function.Consumer<? super PT> action) |
void |
peek(java.util.function.Consumer<? super ST> stAction,
java.util.function.Consumer<? super PT> ptAction) |
static <ST,PT> Xor<ST,PT> |
primary(PT value) |
static <ST,PT> Xor<ST,PT> |
secondary(ST value)
Create an instance of the secondary type.
|
<LT1,RT1> Xor<LT1,RT1> |
secondaryFlatMap(java.util.function.Function<? super ST,? extends Xor<LT1,RT1>> mapper) |
ST |
secondaryGet() |
<R> Xor<R,PT> |
secondaryMap(java.util.function.Function<? super ST,? extends R> fn) |
Xor<ST,PT> |
secondaryPeek(java.util.function.Consumer<? super ST> action) |
java.util.Optional<ST> |
secondaryToOptional() |
Xor<ST,PT> |
secondaryToPrimayFlatMap(java.util.function.Function<? super ST,? extends Xor<ST,PT>> fn) |
Xor<ST,PT> |
secondaryToPrimayMap(java.util.function.Function<? super ST,? extends PT> fn) |
ReactiveSeq<ST> |
secondaryToStream() |
Value<ST> |
secondaryValue() |
static <ST,PT> Xor<ListX<ST>,ListX<PT>> |
sequencePrimary(CollectionX<Xor<ST,PT>> xors) |
static <ST,PT> Xor<ListX<PT>,ListX<ST>> |
sequenceSecondary(CollectionX<Xor<ST,PT>> xors) |
Xor<PT,ST> |
swap() |
Ior<ST,PT> |
toIor() |
default Xor<ST,PT> |
toXor() |
default <R> Xor<ST,R> |
trampoline(java.util.function.Function<? super PT,? extends Trampoline<? extends R>> mapper)
Performs a map operation that can call a recursive method without running out of stack space
|
default <T> Xor<?,T> |
unit(T unit) |
default <R> R |
visit(java.util.function.Function<? super ST,? extends R> secondary,
java.util.function.Function<? super PT,? extends R> primary) |
default <R1,R2> Xor<R1,R2> |
visitXor(java.util.function.Function<? super ST,? extends R1> secondary,
java.util.function.Function<? super PT,? extends R2> primary) |
ap, ap, ap1, ap2, ap3, ap4, ap5
convertTo, convertToAsync, fold, fold, generate, getMatchable, iterate, mkString, newSubscriber, toDequeX, toEvalAlways, toEvalLater, toEvalNow, toFutureStream, toFutureStream, toLazyImmutable, toListX, toMaybe, toMutable, toPBagX, toPOrderedSetX, toPQueueX, toPSetX, toPStackX, toPVectorX, toQueueX, toSetX, toSimpleReact, toSimpleReact, toSortedSetX, toTry, toTry, unapply
foldRight, foldRight, foldRight, foldRightMapToType, join, join, join, mapReduce, print, print, printErr, printOut, reduce, reduce, reduce, reduce, reduce, reduce, reduce
from, from, from, from, from, from, from, from, from, from, fromCharSequence, fromIterable, fromOptional, listOfValues, ofDecomposable, otherwise, otherwise, then, then, when, when, when, when, when, when, when, when, when, when, whenGuard, whenTrue, whenValues
fromSupplier, orElse, orElseGet, orElseThrow, toAtomicReference, toCompletableFuture, toCompletableFutureAsync, toCompletableFutureAsync, toFutureW, toList, toOptional, toOptionalAtomicReference, toStream, visit
static <ST,PT> Xor<ST,PT> secondary(ST value)
Xor.<Integer,Integer>secondary(10).map(i->i+1);
//Xor.secondary[10]
Xor.<Integer,Integer>secondary(10).swap().map(i->i+1);
//Xor.primary[11]
value
- to wrapstatic <ST,PT> Xor<ST,PT> primary(PT value)
Xor<ST,PT> filter(java.util.function.Predicate<? super PT> test)
filter
in interface Filterable<PT>
Xor<ST,PT> secondaryToPrimayMap(java.util.function.Function<? super ST,? extends PT> fn)
static <ST,PT> Xor<ListX<PT>,ListX<ST>> sequenceSecondary(CollectionX<Xor<ST,PT>> xors)
static <ST,PT,R> Xor<?,R> accumulateSecondary(CollectionX<Xor<ST,PT>> xors, Reducer<R> reducer)
static <ST,PT,R> Xor<?,R> accumulateSecondary(CollectionX<Xor<ST,PT>> xors, java.util.function.Function<? super ST,R> mapper, Semigroup<R> reducer)
static <ST,PT> Xor<ListX<ST>,ListX<PT>> sequencePrimary(CollectionX<Xor<ST,PT>> xors)
static <ST,PT,R> Xor<?,R> accumulatePrimary(CollectionX<Xor<ST,PT>> xors, Reducer<R> reducer)
static <ST,PT,R> Xor<?,R> accumulatePrimary(CollectionX<Xor<ST,PT>> xors, java.util.function.Function<? super PT,R> mapper, Semigroup<R> reducer)
static <ST,PT> Xor<?,PT> accumulatePrimary(CollectionX<Xor<ST,PT>> xors, Semigroup<PT> reducer)
static <ST,PT> Xor<?,ST> accumulateSecondary(CollectionX<Xor<ST,PT>> xors, Semigroup<ST> reducer)
Xor.accumulateSecondary(ListX.of(Xor.secondary("failed1"),
Xor.secondary("failed2"),
Xor.primary("success")),
Semigroups.stringConcat)
//Xors.Primary[failed1failed2]
xors
- reducer
- default <R> R visit(java.util.function.Function<? super ST,? extends R> secondary, java.util.function.Function<? super PT,? extends R> primary)
default <R1,R2> Xor<R1,R2> visitXor(java.util.function.Function<? super ST,? extends R1> secondary, java.util.function.Function<? super PT,? extends R2> primary)
default <R> Xor<ST,R> patternMatch(java.util.function.Function<Matchable.CheckValues<PT,R>,Matchable.CheckValues<PT,R>> case1, java.util.function.Supplier<? extends R> otherwise)
Functor
List<String> result = CollectionX.of(1,2,3,4)
.patternMatch(
c->c.valuesWhere(i->"even", (Integer i)->i%2==0 )
)
// CollectionX["odd","even","odd","even"]
patternMatch
in interface Functor<PT>
case1
- Function to generate a case (or chain of cases as a single case)otherwise
- Value if supplied case doesn't match<R> Eval<R> matches(java.util.function.Function<Matchable.CheckValue1<ST,R>,Matchable.CheckValue1<ST,R>> fn1, java.util.function.Function<Matchable.CheckValue1<PT,R>,Matchable.CheckValue1<PT,R>> fn2, java.util.function.Supplier<? extends R> otherwise)
PT get()
get
in interface Convertable<PT>
get
in interface java.util.function.Supplier<PT>
ST secondaryGet()
java.util.Optional<ST> secondaryToOptional()
ReactiveSeq<ST> secondaryToStream()
<LT1,RT1> Xor<LT1,RT1> flatMap(java.util.function.Function<? super PT,? extends Xor<LT1,RT1>> mapper)
<LT1,RT1> Xor<LT1,RT1> secondaryFlatMap(java.util.function.Function<? super ST,? extends Xor<LT1,RT1>> mapper)
Xor<ST,PT> secondaryToPrimayFlatMap(java.util.function.Function<? super ST,? extends Xor<ST,PT>> fn)
void peek(java.util.function.Consumer<? super ST> stAction, java.util.function.Consumer<? super PT> ptAction)
boolean isPrimary()
boolean isSecondary()
default <U> Xor<ST,U> ofType(java.lang.Class<U> type)
Filterable
ofType
in interface Filterable<PT>
default Xor<ST,PT> filterNot(java.util.function.Predicate<? super PT> fn)
filterNot
in interface Filterable<PT>
default <U> Xor<ST,U> cast(java.lang.Class<U> type)
Functor
ClassCastException
.
// ClassCastException ReactiveSeq.of(1, "a", 2, "b", 3).cast(Integer.class)default <R> Xor<ST,R> trampoline(java.util.function.Function<? super PT,? extends Trampoline<? extends R>> mapper)
Functor
ReactiveSeq.of(10,20,30,40)
.trampoline(i-> fibonacci(i))
.forEach(System.out::println);
Trampoline<Long> fibonacci(int i){
return fibonacci(i,1,0);
}
Trampoline<Long> fibonacci(int n, long a, long b) {
return n == 0 ? Trampoline.done(b) : Trampoline.more( ()->fibonacci(n-1, a+b, a));
}
55
6765
832040
102334155
ReactiveSeq.of(10_000,200_000,3_000_000,40_000_000)
.trampoline(i-> fibonacci(i))
.forEach(System.out::println);
completes successfully
trampoline
in interface Functor<PT>