ST - Secondary typePT - Primary typepublic interface Xor<ST,PT> extends To<Xor<ST,PT>>, MonadicValue<PT>, BiTransformable<ST,PT>, Higher2<Witness.xor,ST,PT>
public class Member{
Xor team;
}
Rather than
public class Member{ | Modifier and Type | Interface and Description |
|---|---|
static class |
Xor.Instances |
static class |
Xor.Primary<ST,PT> |
static class |
Xor.Secondary<ST,PT> |
Value.ValueImpl<T>Convertable.SupplierToConvertable<T>Fn0.FunctionalOperations<R>, Fn0.SupplierKind<R>| 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,
Monoid<R> reducer)
Accumulate the results only from those Iors which have a Primary type present, using the supplied mapping function to
convert the data from each Xor before reducing them using the supplied Monoid (a combining BiFunction/BinaryOperator and identity element that takes two
input values of the same type and returns the combined result)
cyclops2.Monoids .. |
static <ST,PT,R> Xor<?,R> |
accumulatePrimary(CollectionX<Xor<ST,PT>> xors,
Reducer<R> reducer)
Accumulate the result of the Primary types in the Collection of Xors provided using the supplied Reducer
cyclops2.Reducers. |
static <ST,PT> Xor<?,PT> |
accumulatePrimary(Monoid<PT> reducer,
CollectionX<Xor<ST,PT>> xors)
Accumulate the results only from those Xors which have a Primary type present, using the supplied Monoid (a combining BiFunction/BinaryOperator and identity element that takes two
input values of the same type and returns the combined result)
cyclops2.Monoids . |
static <ST,PT,R> Xor<?,R> |
accumulateSecondary(CollectionX<Xor<ST,PT>> xors,
java.util.function.Function<? super ST,R> mapper,
Monoid<R> reducer)
Accumulate the results only from those Xors which have a Secondary type present, using the supplied mapping function to
convert the data from each Xor before reducing them using the supplied Monoid (a combining BiFunction/BinaryOperator and identity element that takes two
input values of the same type and returns the combined result)
cyclops2.Monoids .. |
static <ST,PT,R> Xor<?,R> |
accumulateSecondary(CollectionX<Xor<ST,PT>> xors,
Reducer<R> reducer)
Accumulate the result of the Secondary types in the Collection of Xors provided using the supplied Reducer
cyclops2.Reducers. |
static <ST,PT> Xor<?,ST> |
accumulateSecondary(Monoid<ST> reducer,
CollectionX<Xor<ST,PT>> xors)
Accumulate the results only from those Xors which have a Secondary type present, using the supplied Monoid (a combining BiFunction/BinaryOperator and identity element that takes two
input values of the same type and returns the combined result)
cyclops2.Monoids . |
default Active<Higher<Witness.xor,ST>,PT> |
allTypeclasses() |
default AnyMValue<Witness.xor,PT> |
anyM() |
static <X,LT extends X,M extends X,RT extends X,R> |
applyAny(Xor<LT,RT> either) |
default int |
arity() |
default <U1,U2> Xor<U1,U2> |
bicast(java.lang.Class<U1> type1,
java.lang.Class<U2> type2)
Cast two data types simulatanously.
|
default <R1,R2> Xor<R1,R2> |
bimap(java.util.function.Function<? super ST,? extends R1> secondary,
java.util.function.Function<? super PT,? extends R2> primary)
Transform this BiTransformable, changing two value types at once.
|
default Xor<ST,PT> |
bipeek(java.util.function.Consumer<? super ST> c1,
java.util.function.Consumer<? super PT> c2)
Peek at two data types simulatanously (typically to perform a side-effect with each data point)
|
default <R1,R2> Xor<R1,R2> |
bitrampoline(java.util.function.Function<? super ST,? extends Trampoline<? extends R1>> mapper1,
java.util.function.Function<? super PT,? extends Trampoline<? extends R2>> mapper2)
Perform a tail-call optimized recursive transformation operation across two data points simultaneously
|
default <U> Xor<ST,U> |
cast(java.lang.Class<? extends U> type)
Cast all elements in a reactiveStream to a given type, possibly throwing a
ClassCastException. |
default <R> Xor<ST,R> |
coflatMap(java.util.function.Function<? super MonadicValue<PT>,R> mapper)
Perform a coflatMap operation.
|
<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
|
default <T2,R> Xor<ST,R> |
combine(Xor<? extends ST,? extends T2> app,
java.util.function.BinaryOperator<ST> semigroup,
java.util.function.BiFunction<? super PT,? super T2,? extends R> fn)
Accumulate secondary values with the provided BinaryOperator / Semigroup
Semigroups
Primary accumulation only occurs if all phases are primary |
default Xor<ST,PT> |
combineEager(Monoid<PT> monoid,
MonadicValue<? extends PT> v2)
Eagerly combine two MonadicValues using the supplied monoid (@see ApplicativeFunctor for type appropraite i.e.
|
default <T2,R> Xor<LinkedListX<ST>,R> |
combineToList(Xor<ST,? extends T2> app,
java.util.function.BiFunction<? super PT,? super T2,? extends R> fn)
Accumulate secondarys into a LinkedListX (extended Persistent List) and Primary with the supplied combiner function
Primary accumulation only occurs if all phases are primary
|
static <X,LT extends X,M extends X,RT extends X> |
consumeAny(Xor<LT,RT> either)
Static method useful as a method reference for fluent consumption of any value type stored in this Either
(will capture the lowest common type)
|
default <W1> Coproduct<W1,Higher<Witness.xor,ST>,PT> |
coproduct(InstanceDefinitions<W1> def2) |
Xor<ST,PT> |
filter(java.util.function.Predicate<? super PT> test)
Keep only elements for which the supplied predicates hold
e.g.
|
default Xor<ST,PT> |
filterNot(java.util.function.Predicate<? super PT> fn)
Remove any elements for which the predicate holds (inverse operation to filter)
e.g.
|
<RT1> Xor<ST,RT1> |
flatMap(java.util.function.Function<? super PT,? extends MonadicValue<? extends RT1>> mapper)
A flattening transformation operation (@see
Optional.flatMap(Function) |
default <R> Xor<ST,R> |
flatMapI(java.util.function.Function<? super PT,? extends java.lang.Iterable<? extends R>> mapper)
A flattening transformation operation that takes the first value from the returned Iterable.
|
default <R> Xor<ST,R> |
flatMapP(java.util.function.Function<? super PT,? extends org.reactivestreams.Publisher<? extends R>> mapper)
A flattening transformation operation that takes the first value from the returned Publisher.
|
default <R> Xor<ST,R> |
flatMapS(java.util.function.Function<? super PT,? extends java.util.stream.Stream<? extends R>> mapper) |
default <R1,R> Xor<ST,R> |
forEach2(java.util.function.Function<? super PT,? extends MonadicValue<R1>> value1,
java.util.function.BiFunction<? super PT,? super R1,? extends R> yieldingFunction)
Perform a two level nested internal iteration over this MonadicValue and the
supplied MonadicValue
|
default <R1,R> Xor<ST,R> |
forEach2(java.util.function.Function<? super PT,? extends MonadicValue<R1>> value1,
java.util.function.BiFunction<? super PT,? super R1,java.lang.Boolean> filterFunction,
java.util.function.BiFunction<? super PT,? super R1,? extends R> yieldingFunction)
Perform a two level nested internal iteration over this MonadicValue and the
supplied reactiveStream
|
default <T2,R1,R2,R> |
forEach3(java.util.function.Function<? super PT,? extends MonadicValue<R1>> value1,
java.util.function.BiFunction<? super PT,? super R1,? extends MonadicValue<R2>> value2,
Fn3<? super PT,? super R1,? super R2,? extends R> yieldingFunction)
Perform a three level nested internal iteration over this MonadicValue and the
supplied MonadicValues
|
default <T2,R1,R2,R> |
forEach3(java.util.function.Function<? super PT,? extends MonadicValue<R1>> value1,
java.util.function.BiFunction<? super PT,? super R1,? extends MonadicValue<R2>> value2,
Fn3<? super PT,? super R1,? super R2,java.lang.Boolean> filterFunction,
Fn3<? super PT,? super R1,? super R2,? extends R> yieldingFunction)
Perform a three level nested internal iteration over this MonadicValue and the
supplied MonadicValues
|
default <T2,R1,R2,R3,R> |
forEach4(java.util.function.Function<? super PT,? extends MonadicValue<R1>> value1,
java.util.function.BiFunction<? super PT,? super R1,? extends MonadicValue<R2>> value2,
Fn3<? super PT,? super R1,? super R2,? extends MonadicValue<R3>> value3,
Fn4<? super PT,? super R1,? super R2,? super R3,? extends R> yieldingFunction)
Perform a four level nested internal iteration over this MonadicValue and the
supplied MonadicValues
|
default <T2,R1,R2,R3,R> |
forEach4(java.util.function.Function<? super PT,? extends MonadicValue<R1>> value1,
java.util.function.BiFunction<? super PT,? super R1,? extends MonadicValue<R2>> value2,
Fn3<? super PT,? super R1,? super R2,? extends MonadicValue<R3>> value3,
Fn4<? super PT,? super R1,? super R2,? super R3,java.lang.Boolean> filterFunction,
Fn4<? super PT,? super R1,? super R2,? super R3,? extends R> yieldingFunction)
Perform a four level nested internal iteration over this MonadicValue and the
supplied MonadicValues
Maybe.of(3)
.forEach4(a->Maybe.just(a+10),
(a,b)->Maybe.just(a+b),
(a,b,c)->Maybe.none(),
(a,b,c,d)->a+b+c<100,
(a,b,c,d)->a+b+c+d);
//Maybe.none
|
static <ST,T> Xor<ST,T> |
fromIterable(java.lang.Iterable<T> iterable)
Construct a Primary Xor from the supplied Iterable
|
static <T> Xor<java.lang.Throwable,T> |
fromPublisher(org.reactivestreams.Publisher<T> pub)
Construct a Primary Xor from the supplied publisher
|
PT |
get() |
default boolean |
isPresent() |
boolean |
isPrimary() |
boolean |
isSecondary() |
static <L,T> Cokleisli<Higher<Witness.xor,L>,T,Xor<L,T>> |
kindCokleisli() |
static <L,T> Kleisli<Higher<Witness.xor,L>,Xor<L,T>,T> |
kindKleisli() |
default <W extends WitnessType<W>> |
liftM(W witness) |
default Xor<LinkedListX<ST>,PT> |
list() |
<R> Xor<ST,R> |
map(java.util.function.Function<? super PT,? extends R> fn)
Transform this functor using the supplied transformation function
|
default <W2,R> Nested<Higher<Witness.xor,ST>,W2,R> |
mapM(java.util.function.Function<? super PT,? extends Higher<W2,R>> fn,
InstanceDefinitions<W2> defs) |
static <ST,T> Xor<ST,T> |
narrowK(Higher<Higher<Witness.xor,ST>,T> xor) |
static <ST,T> Xor<ST,T> |
narrowK2(Higher2<Witness.xor,ST,T> xor) |
default Xor<ST,MonadicValue<PT>> |
nest()
cojoin pattern.
|
static <W1,ST,PT> Nested<Higher<Witness.xor,ST>,W1,PT> |
nested(Xor<ST,Higher<W1,PT>> nested,
InstanceDefinitions<W1> def2) |
default Eval<Xor<ST,PT>> |
nestedEval() |
default Xor<ST,PT> |
notNull()
Filter elements retaining only values which are not null
|
default <U> Xor<ST,U> |
ofType(java.lang.Class<? extends U> type)
Keep only those elements in a reactiveStream that are of a given type.
|
Xor<ST,PT> |
peek(java.util.function.Consumer<? super PT> action)
Peek at the current value of this Transformable, without transforming it
|
void |
peek(java.util.function.Consumer<? super ST> stAction,
java.util.function.Consumer<? super PT> ptAction)
Deprecated.
|
static <ST,PT> Xor<ST,PT> |
primary(PT value)
Create an instance of the primary type.
|
default <W1> Product<Higher<Witness.xor,ST>,W1,PT> |
product(Active<W1,PT> active) |
default <R> Xor<ST,R> |
retry(java.util.function.Function<? super PT,? extends R> fn)
Retry a transformation if it fails.
|
default <R> Xor<ST,R> |
retry(java.util.function.Function<? super PT,? extends R> fn,
int retries,
long delay,
java.util.concurrent.TimeUnit timeUnit)
Retry a transformation if it fails.
|
static <ST,PT> Xor<ST,PT> |
secondary(ST value)
Create an instance of the secondary type.
|
<LT1> Xor<LT1,PT> |
secondaryFlatMap(java.util.function.Function<? super ST,? extends Xor<LT1,PT>> 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() |
static <ST,PT> Xor<ListX<ST>,ListX<PT>> |
sequencePrimary(CollectionX<Xor<ST,PT>> xors)
Turn a Collection of Xors into a single Xor with Lists of values.
|
static <ST,PT> Xor<ListX<PT>,ListX<ST>> |
sequenceSecondary(CollectionX<Xor<ST,PT>> xors)
Turn a toX of Xors into a singleUnsafe Xor with Lists of values.
|
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
|
default java.util.Optional<PT> |
toOptional() |
default Trampoline<Xor<ST,PT>> |
toTrampoline() |
default Xor<ST,PT> |
toXor() |
default <ST2> Xor<ST2,PT> |
toXor(ST2 secondary)
Convert to an Xor where the secondary value will be used if no primary value is present
|
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<ST,T> |
unit(T unit) |
<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.
|
static <X,LT extends X,RT extends X> |
visitAny(java.util.function.Consumer<? super X> c,
Xor<LT,RT> either) |
static <X,PT extends X,ST extends X,R> |
visitAny(Xor<ST,PT> either,
java.util.function.Function<? super X,? extends R> fn) |
static <L,T> Higher<Higher<Witness.xor,L>,T> |
widen(Xor<L,T> narrow) |
default Xor<ST,PT> |
zip(java.util.function.BinaryOperator<Zippable<PT>> combiner,
Zippable<PT> app)
Combine two applicatives together using the provided BinaryOperator (Semigroup, Monoid and Reducer all
extend BinaryOperator - checkout SemigroupK and Monoids for a large number of canned combinations).
|
default <T2,R> Xor<ST,R> |
zip(java.lang.Iterable<? extends T2> app,
java.util.function.BiFunction<? super PT,? super T2,? extends R> fn)
Zip (combine) this Zippable with the supplied Iterable using the supplied combining function
|
default <U> Xor<ST,org.jooq.lambda.tuple.Tuple2<PT,U>> |
zip(java.lang.Iterable<? extends U> other)
Zip (combine) this Zippable with the supplied Iterable combining both into a Tuple2
|
default <S,U> Xor<ST,org.jooq.lambda.tuple.Tuple3<PT,S,U>> |
zip3(java.lang.Iterable<? extends S> second,
java.lang.Iterable<? extends U> third)
zip 3 Streams into one
|
default <S,U,R> Xor<ST,R> |
zip3(java.lang.Iterable<? extends S> second,
java.lang.Iterable<? extends U> third,
Fn3<? super PT,? super S,? super U,? extends R> fn3) |
default <T2,T3,T4> Xor<ST,org.jooq.lambda.tuple.Tuple4<PT,T2,T3,T4>> |
zip4(java.lang.Iterable<? extends T2> second,
java.lang.Iterable<? extends T3> third,
java.lang.Iterable<? extends T4> fourth)
zip 4 Streams into 1
|
default <T2,T3,T4,R> |
zip4(java.lang.Iterable<? extends T2> second,
java.lang.Iterable<? extends T3> third,
java.lang.Iterable<? extends T4> fourth,
Fn4<? super PT,? super T2,? super T3,? super T4,? extends R> fn) |
default <T2,R> Xor<ST,R> |
zipP(org.reactivestreams.Publisher<? extends T2> app,
java.util.function.BiFunction<? super PT,? super T2,? extends R> fn)
Zip (combine) this Zippable with the supplied Publisher, using the supplied combining function
|
default <U> Xor<ST,org.jooq.lambda.tuple.Tuple2<PT,U>> |
zipP(org.reactivestreams.Publisher<? extends U> other) |
default <U> Xor<ST,org.jooq.lambda.tuple.Tuple2<PT,U>> |
zipS(java.util.stream.Stream<? extends U> other)
Zip (combine) this Zippable with the supplied Stream combining both into a Tuple2
|
default <U,R> Xor<ST,R> |
zipS(java.util.stream.Stream<? extends U> other,
java.util.function.BiFunction<? super PT,? super U,? extends R> zipper)
Zip (combine) this Zippable with the supplied Stream, using the supplied combining function
|
default <R> Xor<ST,R> |
zipWith(java.lang.Iterable<java.util.function.Function<? super PT,? extends R>> fn) |
default <R> Xor<ST,R> |
zipWithP(org.reactivestreams.Publisher<java.util.function.Function<? super PT,? extends R>> fn) |
default <R> Xor<ST,R> |
zipWithS(java.util.stream.Stream<java.util.function.Function<? super PT,? extends R>> fn) |
apply, generate, iterate, iterator, mkString, newSubscriber, of, stream, subscribe, test, toEither, toEval, toEvalAlways, toEvalLater, toEvalNow, toLeft, toMaybe, toMaybeEager, toRight, toTry, toTry, toTryendsWith, endsWithIterable, findAny, findFirst, firstValue, foldLeft, foldLeft, foldLeft, foldLeft, foldRight, foldRight, foldRight, foldRightMapToType, get, groupBy, join, join, join, mapReduce, mapReduce, print, print, printErr, printOut, reduce, reduce, reduce, reduce, reduce, reduce, reduce, schedule, scheduleFixedDelay, scheduleFixedRate, single, single, singleUnsafe, startsWith, startsWithIterable, takeOne, xMatchcollect, fromSupplier, orElse, orElseGet, orElseThrow, toCompletableFuture, toCompletableFutureAsync, toFuture, toFutureAsync, toStream, visitstatic <L,T> Kleisli<Higher<Witness.xor,L>,Xor<L,T>,T> kindKleisli()
static <L,T> Higher<Higher<Witness.xor,L>,T> widen(Xor<L,T> narrow)
static <L,T> Cokleisli<Higher<Witness.xor,L>,T,Xor<L,T>> kindCokleisli()
static <W1,ST,PT> Nested<Higher<Witness.xor,ST>,W1,PT> nested(Xor<ST,Higher<W1,PT>> nested, InstanceDefinitions<W1> def2)
default <W1> Coproduct<W1,Higher<Witness.xor,ST>,PT> coproduct(InstanceDefinitions<W1> def2)
default Active<Higher<Witness.xor,ST>,PT> allTypeclasses()
default <W2,R> Nested<Higher<Witness.xor,ST>,W2,R> mapM(java.util.function.Function<? super PT,? extends Higher<W2,R>> fn, InstanceDefinitions<W2> defs)
default <W extends WitnessType<W>> XorT<W,ST,PT> liftM(W witness)
static <X,LT extends X,M extends X,RT extends X> java.util.function.Consumer<java.util.function.Consumer<? super X>> consumeAny(Xor<LT,RT> either)
myEither.to(Xor::consumeAny)
.accept(System.out::println);
either - Xor to consume value forstatic <X,LT extends X,M extends X,RT extends X,R> java.util.function.Function<java.util.function.Function<? super X,R>,R> applyAny(Xor<LT,RT> either)
static <X,PT extends X,ST extends X,R> R visitAny(Xor<ST,PT> either, java.util.function.Function<? super X,? extends R> fn)
static <X,LT extends X,RT extends X> X visitAny(java.util.function.Consumer<? super X> c,
Xor<LT,RT> either)
static <ST,T> Xor<ST,T> narrowK2(Higher2<Witness.xor,ST,T> xor)
static <ST,T> Xor<ST,T> narrowK(Higher<Higher<Witness.xor,ST>,T> xor)
static <T> Xor<java.lang.Throwable,T> fromPublisher(org.reactivestreams.Publisher<T> pub)
ReactiveSeq<Integer> reactiveStream = ReactiveSeq.of(1,2,3);
Xor<Throwable,Integer> future = Xor.fromPublisher(reactiveStream);
//Xor[1]
pub - Publisher to construct an Xor fromstatic <ST,T> Xor<ST,T> fromIterable(java.lang.Iterable<T> iterable)
List<Integer> list = Arrays.asList(1,2,3);
Xor<Throwable,Integer> future = Xor.fromPublisher(reactiveStream);
//Xor[1]
iterable - Iterable to construct an Xor fromstatic <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.<Integer,Integer>primary(10).map(i->i+1);
//Xor.primary[11]
value - To construct an Xor fromdefault int arity()
arity in interface MonadicValue<PT>default <R> Xor<ST,R> zipWith(java.lang.Iterable<java.util.function.Function<? super PT,? extends R>> fn)
default <R> Xor<ST,R> zipWithS(java.util.stream.Stream<java.util.function.Function<? super PT,? extends R>> fn)
default <R> Xor<ST,R> zipWithP(org.reactivestreams.Publisher<java.util.function.Function<? super PT,? extends R>> fn)
default <R> Xor<ST,R> retry(java.util.function.Function<? super PT,? extends R> fn)
Transformable
given(serviceMock.applyHKT(anyInt())).willThrow(
new RuntimeException(new SocketException("First")),
new RuntimeException(new IOException("Second"))).willReturn(
"42");
String result = ReactiveSeq.of( 1, 2, 3)
.retry(serviceMock)
.firstValue();
//result = 42
retry in interface Transformable<PT>fn - Function to retry if failsdefault <U> Xor<ST,org.jooq.lambda.tuple.Tuple2<PT,U>> zipP(org.reactivestreams.Publisher<? extends U> other)
default <R> Xor<ST,R> retry(java.util.function.Function<? super PT,? extends R> fn, int retries, long delay, java.util.concurrent.TimeUnit timeUnit)
Transformable
given(serviceMock.applyHKT(anyInt())).willThrow(
new RuntimeException(new SocketException("First")),
new RuntimeException(new IOException("Second"))).willReturn(
"42");
String result = ReactiveSeq.of( 1, 2, 3)
.retry(serviceMock, 7, 2, TimeUnit.SECONDS)
.firstValue();
//result = 42
retry in interface Transformable<PT>fn - Function to retry if failsretries - Number of retriesdelay - Delay in TimeUnitstimeUnit - TimeUnit to use for delaydefault <S,U> Xor<ST,org.jooq.lambda.tuple.Tuple3<PT,S,U>> zip3(java.lang.Iterable<? extends S> second, java.lang.Iterable<? extends U> third)
Zippable
List<Tuple3<Integer, Integer, Character>> list = of(1, 2, 3, 4, 5, 6).zip3(of(100, 200, 300, 400), of('a', 'b', 'c')).collect(CyclopsCollectors.toList());
// [[1,100,'a'],[2,200,'b'],[3,300,'c']]
default <S,U,R> Xor<ST,R> zip3(java.lang.Iterable<? extends S> second, java.lang.Iterable<? extends U> third, Fn3<? super PT,? super S,? super U,? extends R> fn3)
default <T2,T3,T4> Xor<ST,org.jooq.lambda.tuple.Tuple4<PT,T2,T3,T4>> zip4(java.lang.Iterable<? extends T2> second, java.lang.Iterable<? extends T3> third, java.lang.Iterable<? extends T4> fourth)
Zippable
List<Tuple4<Integer, Integer, Character, String>> list = of(1, 2, 3, 4, 5, 6).zip4(of(100, 200, 300, 400), of('a', 'b', 'c'), of("hello", "world"))
.collect(CyclopsCollectors.toList());
// [[1,100,'a',"hello"],[2,200,'b',"world"]]
default <T2,T3,T4,R> Xor<ST,R> zip4(java.lang.Iterable<? extends T2> second, java.lang.Iterable<? extends T3> third, java.lang.Iterable<? extends T4> fourth, Fn4<? super PT,? super T2,? super T3,? super T4,? extends R> fn)
default <R> Xor<ST,R> flatMapS(java.util.function.Function<? super PT,? extends java.util.stream.Stream<? extends R>> mapper)
flatMapS in interface MonadicValue<PT>default <T2,R1,R2,R3,R> Xor<ST,R> forEach4(java.util.function.Function<? super PT,? extends MonadicValue<R1>> value1, java.util.function.BiFunction<? super PT,? super R1,? extends MonadicValue<R2>> value2, Fn3<? super PT,? super R1,? super R2,? extends MonadicValue<R3>> value3, Fn4<? super PT,? super R1,? super R2,? super R3,? extends R> yieldingFunction)
MonadicValue
Maybe.of(3)
.forEach4(a->Maybe.just(a+10),
(a,b)->Maybe.just(a+b),
(a,b,c)->Maybe.none(),
(a,b,c,d)->a+b+c+d);
//Maybe.none
forEach4 in interface MonadicValue<PT>value1 - Nested MonadicValue to iterate overvalue2 - Nested MonadicValue to iterate overvalue3 - Nested MonadicValue to iterate overyieldingFunction - Function with pointers to the current element from both
MonadicValue that generates the new elementsdefault <T2,R1,R2,R3,R> Xor<ST,R> forEach4(java.util.function.Function<? super PT,? extends MonadicValue<R1>> value1, java.util.function.BiFunction<? super PT,? super R1,? extends MonadicValue<R2>> value2, Fn3<? super PT,? super R1,? super R2,? extends MonadicValue<R3>> value3, Fn4<? super PT,? super R1,? super R2,? super R3,java.lang.Boolean> filterFunction, Fn4<? super PT,? super R1,? super R2,? super R3,? extends R> yieldingFunction)
MonadicValueMaybe.of(3)
.forEach4(a->Maybe.just(a+10),
(a,b)->Maybe.just(a+b),
(a,b,c)->Maybe.none(),
(a,b,c,d)->a+b+c<100,
(a,b,c,d)->a+b+c+d);
//Maybe.none
forEach4 in interface MonadicValue<PT>value1 - Nested MonadicValue to iterate overvalue2 - Nested MonadicValue to iterate overvalue3 - Nested MonadicValue to iterate overfilterFunction - Filter to applyHKT over elements before passing non-filtered
values to the yielding functionyieldingFunction - Function with pointers to the current element from both
MonadicValue that generates the new elementsdefault <T2,R1,R2,R> Xor<ST,R> forEach3(java.util.function.Function<? super PT,? extends MonadicValue<R1>> value1, java.util.function.BiFunction<? super PT,? super R1,? extends MonadicValue<R2>> value2, Fn3<? super PT,? super R1,? super R2,? extends R> yieldingFunction)
MonadicValue
Maybe.of(3)
.forEach3(a->Maybe.just(a+10),
(a,b)->Maybe.just(a+b),
(a,b,c)->a+b+c<100,
(a,b,c)->a+b+c);
//Maybe[32]
forEach3 in interface MonadicValue<PT>value1 - Nested MonadicValue to iterate overvalue2 - Nested MonadicValue to iterate overyieldingFunction - Function with pointers to the current element from both
MonadicValue that generates the new elementsdefault <T2,R1,R2,R> Xor<ST,R> forEach3(java.util.function.Function<? super PT,? extends MonadicValue<R1>> value1, java.util.function.BiFunction<? super PT,? super R1,? extends MonadicValue<R2>> value2, Fn3<? super PT,? super R1,? super R2,java.lang.Boolean> filterFunction, Fn3<? super PT,? super R1,? super R2,? extends R> yieldingFunction)
MonadicValue
Maybe.of(3)
.forEach3(a->Maybe.just(a+10),
(a,b)->Maybe.just(a+b),
(a,b,c)->a+b+c<100,
(a,b,c)->a+b+c);
//Maybe[32]
forEach3 in interface MonadicValue<PT>value1 - Nested MonadicValue to iterate overvalue2 - Nested MonadicValue to iterate overfilterFunction - Filter to applyHKT over elements before passing non-filtered
values to the yielding functionyieldingFunction - Function with pointers to the current element from both
MonadicValue that generates the new elementsdefault <R1,R> Xor<ST,R> forEach2(java.util.function.Function<? super PT,? extends MonadicValue<R1>> value1, java.util.function.BiFunction<? super PT,? super R1,? extends R> yieldingFunction)
MonadicValue
Maybe.of(3)
.forEach2(a->Maybe.none(),
(a,b)->a+b);
//Maybe.none()
forEach2 in interface MonadicValue<PT>value1 - Nested Monadic Type to iterate overyieldingFunction - Function with pointers to the current element from both
monad types that generates the new elementsdefault <R1,R> Xor<ST,R> forEach2(java.util.function.Function<? super PT,? extends MonadicValue<R1>> value1, java.util.function.BiFunction<? super PT,? super R1,java.lang.Boolean> filterFunction, java.util.function.BiFunction<? super PT,? super R1,? extends R> yieldingFunction)
MonadicValue
Maybe.of(3)
.forEach2(a->Maybe.none(),
a->b-> a<3 && b>10,
(a,b)->a+b);
//Maybe.none()
forEach2 in interface MonadicValue<PT>filterFunction - Filter to applyHKT over elements before passing non-filtered
values to the yielding functionyieldingFunction - Function with pointers to the current element from both
Streams that generates the new elementsdefault AnyMValue<Witness.xor,PT> anyM()
default Xor<ST,PT> zip(java.util.function.BinaryOperator<Zippable<PT>> combiner, Zippable<PT> app)
Zippablezip in interface Zippable<PT>Semigroup,
Semigroups,
Monoid,
To lift any Semigroup (or monoid) up to handling Applicatives use the combineApplicatives operator in SemigroupK
{@see com.aol.cyclops2.SemigroupK#combineApplicatives(BiFunction) } or Monoids
{ {@see com.aol.cyclops2.Monoids#combineApplicatives(java.util.function.Function, com.aol.cyclops2.function.Monoid)
}
{@code
BinaryOperator> sumMaybes = SemigroupK.combineScalarFunctors(SemigroupK.intSum);
Maybe.just(1).zip(sumMaybes, Maybe.just(5))
//Maybe.just(6));
}
default <R> Xor<ST,R> flatMapI(java.util.function.Function<? super PT,? extends java.lang.Iterable<? extends R>> mapper)
MonadicValue
Maybe.just(1).map(i->i+2).flatMapI(i->Arrays.asList(()->i*3,20);
//Maybe[9]
flatMapI in interface MonadicValue<PT>mapper - transformation functiondefault <R> Xor<ST,R> flatMapP(java.util.function.Function<? super PT,? extends org.reactivestreams.Publisher<? extends R>> mapper)
MonadicValue
Future.ofResult(1).map(i->i+2).flatMapP(i->Flux.just(()->i*3,20);
//Future[9]
flatMapP in interface MonadicValue<PT>mapper - transformation functiondefault <R> Xor<ST,R> coflatMap(java.util.function.Function<? super MonadicValue<PT>,R> mapper)
MonadicValue
Maybe.none().coflatMap(m -> m.isPresent() ? m.get() : 10);
//Maybe[10]
coflatMap in interface MonadicValue<PT>mapper - Mapping / transformation functiondefault Xor<ST,MonadicValue<PT>> nest()
MonadicValuenest in interface MonadicValue<PT>default Xor<ST,PT> combineEager(Monoid<PT> monoid, MonadicValue<? extends PT> v2)
MonadicValue
Monoid<Integer> add = Monoid.of(1,SemigroupK.intSum);
Maybe.of(10).combineEager(add,Maybe.none());
//Maybe[10]
Maybe.none().combineEager(add,Maybe.of(10));
//Maybe[10]
Maybe.none().combineEager(add,Maybe.none());
//Maybe.none()
Maybe.of(10).combineEager(add,Maybe.of(10));
//Maybe[20]
Monoid<Integer> firstNonNull = Monoid.of(null , SemigroupK.firstNonNull());
Maybe.of(10).combineEager(firstNonNull,Maybe.of(10));
//Maybe[10]
combineEager in interface MonadicValue<PT>default java.util.Optional<PT> toOptional()
toOptional in interface Convertable<PT>Xor<ST,PT> filter(java.util.function.Predicate<? super PT> test)
Filters
of(1,2,3).filter(i->i>2);
//[3]
Xor<ST,PT> secondaryToPrimayMap(java.util.function.Function<? super ST,? extends PT> fn)
fn - Function to map secondary type to primary<R> Xor<R,PT> secondaryMap(java.util.function.Function<? super ST,? extends R> fn)
fn - Transformation function for Secondary types<R> Xor<ST,R> map(java.util.function.Function<? super PT,? extends R> fn)
Transformable
of(1,2,3).map(i->i*2)
//[2,4,6]
map in interface MonadicValue<PT>map in interface Transformable<PT>fn - Transformation functionXor<ST,PT> secondaryPeek(java.util.function.Consumer<? super ST> action)
action - Consumer to peek at the Secondary type valueXor<ST,PT> peek(java.util.function.Consumer<? super PT> action)
Transformable
of(1,2,3).map(System.out::println)
1
2
3
peek in interface Transformable<PT>action - Consumer that recieves each element from this TransformableXor<PT,ST> swap()
Xor.secondary("hello")
.map(v->v+" world")
//Xor.seconary["hello"]
Xor.secondary("hello")
.swap()
.map(v->v+" world")
.swap()
//Xor.seconary["hello world"]
Ior<ST,PT> toIor()
Valuedefault boolean isPresent()
isPresent in interface Convertable<PT>default <ST2> Xor<ST2,PT> toXor(ST2 secondary)
Valuestatic <ST,PT> Xor<ListX<PT>,ListX<ST>> sequenceSecondary(CollectionX<Xor<ST,PT>> xors)
Xor<String,Integer> just = Xor.primary(10);
Xor<String,Integer> none = Xor.secondary("none");
Xor<ListX<Integer>,ListX<String>> xors =Xor.sequenceSecondary(ListX.of(just,none,Xor.primary(1)));
//Xor.primary(ListX.of("none")))
xors - Xors to sequencestatic <ST,PT,R> Xor<?,R> accumulateSecondary(CollectionX<Xor<ST,PT>> xors, Reducer<R> reducer)
cyclops2.Reducers.
Xor<String,Integer> just = Xor.primary(10);
Xor<String,Integer> none = Xor.secondary("none");
Xor<?,PersistentSetX<String>> xors = Xor.accumulateSecondary(ListX.of(just,none,Xor.primary(1)),Reducers.<String>toPersistentSetX());
//Xor.primary(PersistentSetX.of("none"))));
xors - Collection of Iors to accumulate secondary valuesreducer - Reducer to accumulate resultsstatic <ST,PT,R> Xor<?,R> accumulateSecondary(CollectionX<Xor<ST,PT>> xors, java.util.function.Function<? super ST,R> mapper, Monoid<R> reducer)
cyclops2.Monoids ..
Xor<String,Integer> just = Xor.primary(10);
Xor<String,Integer> none = Xor.secondary("none");
Xor<?,String> xors = Xor.accumulateSecondary(ListX.of(just,none,Xor.secondary("1")),i->""+i,Monoids.stringConcat);
//Xor.primary("none1")
xors - Collection of Iors to accumulate secondary valuesmapper - Mapping function to be applied to the result of each Iorreducer - Semigroup to combine values from each Iorstatic <ST,PT> Xor<ListX<ST>,ListX<PT>> sequencePrimary(CollectionX<Xor<ST,PT>> xors)
Xor<String,Integer> just = Xor.primary(10);
Xor<String,Integer> none = Xor.secondary("none");
Xor<ListX<String>,ListX<Integer>> xors =Xor.sequencePrimary(ListX.of(just,none,Xor.primary(1)));
//Xor.primary(ListX.of(10,1)));
iors - Xors to sequencestatic <ST,PT,R> Xor<?,R> accumulatePrimary(CollectionX<Xor<ST,PT>> xors, Reducer<R> reducer)
cyclops2.Reducers.
Xor<String,Integer> just = Xor.primary(10);
Xor<String,Integer> none = Xor.secondary("none");
Xor<?,PersistentSetX<Integer>> xors =Xor.accumulatePrimary(ListX.of(just,none,Xor.primary(1)),Reducers.toPersistentSetX());
//Xor.primary(PersistentSetX.of(10,1))));
Xors - Collection of Iors to accumulate primary valuesreducer - Reducer to accumulate resultsstatic <ST,PT,R> Xor<?,R> accumulatePrimary(CollectionX<Xor<ST,PT>> xors, java.util.function.Function<? super PT,R> mapper, Monoid<R> reducer)
cyclops2.Monoids ..
Xor<String,Integer> just = Xor.primary(10);
Xor<String,Integer> none = Xor.secondary("none");
Xor<?,String> iors = Xor.accumulatePrimary(ListX.of(just,none,Xor.primary(1)),i->""+i,Monoids.stringConcat);
//Xor.primary("101"));
xors - Collection of Iors to accumulate primary valuesmapper - Mapping function to be applied to the result of each Iorreducer - Reducer to accumulate resultsstatic <ST,PT> Xor<?,PT> accumulatePrimary(Monoid<PT> reducer, CollectionX<Xor<ST,PT>> xors)
cyclops2.Monoids .
Xor<String,Integer> just = Xor.primary(10);
Xor<String,Integer> none = Xor.secondary("none");
Xor<?,Integer> xors XIor.accumulatePrimary(Monoids.intSum,ListX.of(just,none,Ior.primary(1)));
//Ior.primary(11);
xors - Collection of Xors to accumulate primary valuesreducer - Reducer to accumulate resultsstatic <ST,PT> Xor<?,ST> accumulateSecondary(Monoid<ST> reducer, CollectionX<Xor<ST,PT>> xors)
cyclops2.Monoids .
Xor.accumulateSecondary(ListX.of(Xor.secondary("failed1"),
Xor.secondary("failed2"),
Xor.primary("success")),
SemigroupK.stringConcat)
//Xors.Primary[failed1failed2]
Xor<String,Integer> just = Xor.primary(10);
Xor<String,Integer> none = Xor.secondary("none");
Xor<?,Integer> iors = Xor.accumulateSecondary(Monoids.intSum,ListX.of(Xor.both(2, "boo!"),Xor.secondary(1)));
//Xor.primary(3); 2+1
xors - Collection of Xors to accumulate secondary valuesreducer - Semigroup to combine values from each Xor<R> R visit(java.util.function.Function<? super ST,? extends R> secondary, java.util.function.Function<? super PT,? extends R> primary)
Xor.primary(10)
.visit(secondary->"no", primary->"yes")
//Xor["yes"]
Xor.secondary(90)
.visit(secondary->"no", primary->"yes")
//Xor["no"]
secondary - Function to execute if this is a Secondary Xorprimary - Function to execute if this is a Primary Iorboth - Function to execute if this Ior contains both typesdefault <R1,R2> Xor<R1,R2> bimap(java.util.function.Function<? super ST,? extends R1> secondary, java.util.function.Function<? super PT,? extends R2> primary)
BiTransformable
MapX<String,Integer> map = MapXs.of("hello",2);
MapX<String,Integer> transformedMap = map.bimap(s->s+" world",i->i*4);
//["hello world",8]
bimap in interface BiTransformable<ST,PT>secondary - transformation function for the first typeprimary - transformation function for the second typedefault Xor<ST,PT> bipeek(java.util.function.Consumer<? super ST> c1, java.util.function.Consumer<? super PT> c2)
BiTransformable
MapX<String,Integer> map = MapXs.of("hello",2);
map.bipeek(s->System.out.pritnln("key = " + s),System.out::println);
bipeek in interface BiTransformable<ST,PT>c1 - consumer for the first typec2 - consumer for the second typedefault <U1,U2> Xor<U1,U2> bicast(java.lang.Class<U1> type1, java.lang.Class<U2> type2)
BiTransformable
MapX<Animal,Food> map = MapXs.of(cow,grass);
MapX<Mamaml,Vegitation> herbervoreMammals = map.bicast(Mammal.class,Vegitation.class);
bicast in interface BiTransformable<ST,PT>default <R1,R2> Xor<R1,R2> bitrampoline(java.util.function.Function<? super ST,? extends Trampoline<? extends R1>> mapper1, java.util.function.Function<? super PT,? extends Trampoline<? extends R2>> mapper2)
BiTransformablebitrampoline in interface BiTransformable<ST,PT>mapper1 - transformation function for the first typemapper2 - transformation function for the second typePT get()
get in interface Convertable<PT>get in interface java.util.function.Supplier<PT>Value<ST> secondaryValue()
ST secondaryGet()
java.util.Optional<ST> secondaryToOptional()
ReactiveSeq<ST> secondaryToStream()
<RT1> Xor<ST,RT1> flatMap(java.util.function.Function<? super PT,? extends MonadicValue<? extends RT1>> mapper)
MonadicValueOptional.flatMap(Function)
Eval.now(1).map(i->i+2).flatMap(i->Eval.later(()->i*3);
//Eval[9]
flatMap in interface MonadicValue<PT>mapper - transformation function<LT1> Xor<LT1,PT> secondaryFlatMap(java.util.function.Function<? super ST,? extends Xor<LT1,PT>> mapper)
mapper - Flattening transformation functionXor<ST,PT> secondaryToPrimayFlatMap(java.util.function.Function<? super ST,? extends Xor<ST,PT>> fn)
fn - Transformation function@Deprecated void peek(java.util.function.Consumer<? super ST> stAction, java.util.function.Consumer<? super PT> ptAction)
boolean isPrimary()
boolean isSecondary()
<T2,R> Xor<ST,R> combine(Value<? extends T2> app, java.util.function.BiFunction<? super PT,? super T2,? extends R> fn)
MonadicValue
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
combine in interface MonadicValue<PT>app - Value to combine with this one.fn - BiFunction to combine themdefault Xor<LinkedListX<ST>,PT> list()
Xor#combine(Xor,BiFunction)default <T2,R> Xor<LinkedListX<ST>,R> combineToList(Xor<ST,? extends T2> app, java.util.function.BiFunction<? super PT,? super T2,? extends R> fn)
app - Value to combine withfn - Combiner function for primary valuesdefault <T2,R> Xor<ST,R> combine(Xor<? extends ST,? extends T2> app, java.util.function.BinaryOperator<ST> semigroup, java.util.function.BiFunction<? super PT,? super T2,? extends R> fn)
Semigroups
Primary accumulation only occurs if all phases are primary
Xor<String,String> fail1 = Xor.secondary("failed1");
Xor<LinkedListX<String>,String> result = fail1.list().combine(Xor.secondary("failed2").list(), SemigroupK.collectionConcat(),(a,b)->a+b);
//Secondary of [LinkedListX.of("failed1","failed2")))]
app - Value to combine withsemigroup - to combine secondary typesfn - To combine primary typesdefault <T2,R> Xor<ST,R> zip(java.lang.Iterable<? extends T2> app, java.util.function.BiFunction<? super PT,? super T2,? extends R> fn)
Zippabledefault <T2,R> Xor<ST,R> zipP(org.reactivestreams.Publisher<? extends T2> app, java.util.function.BiFunction<? super PT,? super T2,? extends R> fn)
Zippabledefault <U,R> Xor<ST,R> zipS(java.util.stream.Stream<? extends U> other, java.util.function.BiFunction<? super PT,? super U,? extends R> zipper)
Zippabledefault <U> Xor<ST,org.jooq.lambda.tuple.Tuple2<PT,U>> zipS(java.util.stream.Stream<? extends U> other)
Zippabledefault <U> Xor<ST,org.jooq.lambda.tuple.Tuple2<PT,U>> zip(java.lang.Iterable<? extends U> other)
Zippabledefault <U> Xor<ST,U> ofType(java.lang.Class<? extends U> type)
Filters
// (1, 2, 3) ReactiveSeq.of(1, "a", 2, "b",3).ofType(Integer.class)
default Xor<ST,PT> filterNot(java.util.function.Predicate<? super PT> fn)
Filters
of(1,2,3).filter(i->i>2);
//[1,2]
default Xor<ST,PT> notNull()
Filters
of(1,2,null,4).nonNull();
//[1,2,4]
default <U> Xor<ST,U> cast(java.lang.Class<? extends U> type)
TransformableClassCastException.
// ClassCastException ReactiveSeq.of(1, "a", 2, "b", 3).cast(Integer.class)cast in interface Transformable<PT>default <R> Xor<ST,R> trampoline(java.util.function.Function<? super PT,? extends Trampoline<? extends R>> mapper)
Transformable
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 Transformable<PT>mapper - TCO Transformation functiondefault Trampoline<Xor<ST,PT>> toTrampoline()