W1 - Witness type of monadW2 - Witness type of monadT - Data typepublic class XorM<W1 extends WitnessType<W1>,W2 extends WitnessType<W2>,T> extends java.lang.Object implements Filters<T>, Transformable<T>, Folds<T>, Zippable<T>, org.reactivestreams.Publisher<T>, To<XorM<W1,W2,T>>
XorM<stream,optional,Integer> nums = XorM.stream(1,2,3)
.swap();
int result = nums.map(i->i*2)
.foldLeft(Monoids.intSum);
//12
| Constructor and Description |
|---|
XorM() |
| Modifier and Type | Method and Description |
|---|---|
<U> XorM<W1,W2,U> |
cast(java.lang.Class<? extends U> type)
Cast all elements in a reactiveStream to a given type, possibly throwing a
ClassCastException. |
<R> XorM<W1,W2,R> |
coflatMap(java.util.function.Function<? super XorM<W1,W2,T>,R> mapper) |
static <W1 extends WitnessType<W1>,T> |
completableFutureOf(java.util.function.Supplier<T> value,
java.util.concurrent.Executor ex) |
static <W1 extends WitnessType<W1>,X extends java.lang.Throwable,T> |
failure(X value) |
XorM<W1,W2,T> |
filter(java.util.function.Predicate<? super T> test)
Keep only elements for which the supplied predicates hold
e.g.
|
XorM<W1,W2,T> |
filterNot(java.util.function.Predicate<? super T> predicate)
Remove any elements for which the predicate holds (inverse operation to filter)
e.g.
|
static <W1 extends WitnessType<W1>,T> |
futureOf(java.util.function.Supplier<T> value,
java.util.concurrent.Executor ex) |
java.util.Iterator<T> |
iterator() |
static <W1 extends WitnessType<W1>,T> |
just(T value) |
static <W1 extends WitnessType<W1>,T> |
later(java.util.function.Supplier<T> value) |
static <W1 extends WitnessType<W1>,W2 extends WitnessType<W2>,T> |
left(AnyM<W1,T> left) |
static <W1 extends WitnessType<W1>,T> |
linkedListX(LinkedListX<T> list) |
static <W1 extends WitnessType<W1>,T> |
linkedListX(T... values) |
static <W1 extends WitnessType<W1>,T> |
listX(java.util.List<T> list) |
static <W1 extends WitnessType<W1>,T> |
listX(T... values) |
<R> XorM<W1,W2,R> |
map(java.util.function.Function<? super T,? extends R> fn)
Transform this functor using the supplied transformation function
|
static <W1 extends WitnessType<W1>,T> |
maybeNullabe(T value) |
static <W1 extends WitnessType<W1>,T> |
none() |
XorM<W1,W2,T> |
notNull()
Filter elements retaining only values which are not null
|
static <W1 extends WitnessType<W1>,W2 extends WitnessType<W2>,T> |
of(Xor<? extends AnyM<? extends W1,? extends T>,? extends AnyM<? extends W2,? extends T>> xor) |
static <W1 extends WitnessType<W1>,T> |
ofNullable(T value) |
<U> XorM<W1,W2,U> |
ofType(java.lang.Class<? extends U> type)
Keep only those elements in a reactiveStream that are of a given type.
|
XorM<W1,W2,T> |
peek(java.util.function.Consumer<? super T> c)
Peek at the current value of this Transformable, without transforming it
|
static <W1 extends WitnessType<W1>,T> |
persistentsetX(PersistentSetX<T> list) |
static <W1 extends WitnessType<W1>,T> |
persistentsetX(T... values) |
static <W1 extends WitnessType<W1>,T> |
reactiveSeq(ReactiveSeq<T> stream) |
static <W1 extends WitnessType<W1>,T> |
reactiveSeq(T... values) |
<R> XorM<W1,W2,R> |
retry(java.util.function.Function<? super T,? extends R> fn)
Retry a transformation if it fails.
|
<R> XorM<W1,W2,R> |
retry(java.util.function.Function<? super T,? extends R> fn,
int retries,
long delay,
java.util.concurrent.TimeUnit timeUnit)
Retry a transformation if it fails.
|
static <W1 extends WitnessType<W1>,W2 extends WitnessType<W2>,T> |
right(AnyM<W2,T> right) |
static <W1 extends WitnessType<W1>,T> |
setX(java.util.Set<T> list) |
static <W1 extends WitnessType<W1>,T> |
setX(T... values) |
ReactiveSeq<T> |
stream() |
static <W1 extends WitnessType<W1>,T> |
stream(java.util.stream.Stream<T> stream) |
static <W1 extends WitnessType<W1>,T> |
stream(T... values) |
void |
subscribe(org.reactivestreams.Subscriber<? super T> s) |
static <W1 extends WitnessType<W1>,T> |
success(T value) |
XorM<W2,W1,T> |
swap() |
java.lang.String |
toString() |
<R> XorM<W1,W2,R> |
trampoline(java.util.function.Function<? super T,? extends Trampoline<? extends R>> mapper)
Performs a map operation that can call a recursive method without running out of stack space
|
static <W1 extends WitnessType<W1>,T> |
vectorX(T... values) |
static <W1 extends WitnessType<W1>,T> |
vectorX(VectorX<T> list) |
<R> R |
visit(java.util.function.Function<? super AnyM<W1,? super T>,? extends R> left,
java.util.function.Function<? super AnyM<W2,? super T>,? extends R> right) |
XorM<W1,W2,T> |
zip(java.util.function.BinaryOperator<Zippable<T>> combiner,
Zippable<T> 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).
|
<T2,R> XorM<W1,W2,R> |
zip(java.lang.Iterable<? extends T2> iterable,
java.util.function.BiFunction<? super T,? super T2,? extends R> fn)
Zip (combine) this Zippable with the supplied Iterable using the supplied combining function
|
<U> XorM<W1,W2,org.jooq.lambda.tuple.Tuple2<T,U>> |
zip(java.lang.Iterable<? extends U> other)
Zip (combine) this Zippable with the supplied Iterable combining both into a Tuple2
|
<S,U> XorM<W1,W2,org.jooq.lambda.tuple.Tuple3<T,S,U>> |
zip3(java.lang.Iterable<? extends S> second,
java.lang.Iterable<? extends U> third)
zip 3 Streams into one
|
<S,U,R> XorM<W1,W2,R> |
zip3(java.lang.Iterable<? extends S> second,
java.lang.Iterable<? extends U> third,
Fn3<? super T,? super S,? super U,? extends R> fn3) |
<T2,T3,T4> XorM<W1,W2,org.jooq.lambda.tuple.Tuple4<T,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
|
<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 T,? super T2,? super T3,? super T4,? extends R> fn) |
<T2,R> XorM<W1,W2,R> |
zipP(org.reactivestreams.Publisher<? extends T2> publisher,
java.util.function.BiFunction<? super T,? super T2,? extends R> fn)
Zip (combine) this Zippable with the supplied Publisher, using the supplied combining function
|
<U> XorM<W1,W2,org.jooq.lambda.tuple.Tuple2<T,U>> |
zipP(org.reactivestreams.Publisher<? extends U> other) |
<U> XorM<W1,W2,org.jooq.lambda.tuple.Tuple2<T,U>> |
zipS(java.util.stream.Stream<? extends U> other)
Zip (combine) this Zippable with the supplied Stream combining both into a Tuple2
|
<U,R> XorM<W1,W2,R> |
zipS(java.util.stream.Stream<? extends U> other,
java.util.function.BiFunction<? super T,? super U,? extends R> zipper)
Zip (combine) this Zippable with the supplied Stream, using the supplied combining function
|
<R> XorM<W1,W2,R> |
zipWith(java.lang.Iterable<java.util.function.Function<? super T,? extends R>> fn) |
<R> XorM<W1,W2,R> |
zipWithP(org.reactivestreams.Publisher<java.util.function.Function<? super T,? extends R>> fn) |
<R> XorM<W1,W2,R> |
zipWithS(java.util.stream.Stream<java.util.function.Function<? super T,? extends R>> fn) |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitendsWith, 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, xMatchpublic static <W1 extends WitnessType<W1>,W2 extends WitnessType<W2>,T> XorM<W1,W2,T> of(Xor<? extends AnyM<? extends W1,? extends T>,? extends AnyM<? extends W2,? extends T>> xor)
public static <W1 extends WitnessType<W1>,W2 extends WitnessType<W2>,T> XorM<W1,W2,T> right(AnyM<W2,T> right)
public static <W1 extends WitnessType<W1>,W2 extends WitnessType<W2>,T> XorM<W1,W2,T> left(AnyM<W1,T> left)
public XorM<W1,W2,T> filter(java.util.function.Predicate<? super T> test)
Filters
of(1,2,3).filter(i->i>2);
//[3]
public <R> XorM<W1,W2,R> coflatMap(java.util.function.Function<? super XorM<W1,W2,T>,R> mapper)
public <U> XorM<W1,W2,U> ofType(java.lang.Class<? extends U> type)
Filters
// (1, 2, 3) ReactiveSeq.of(1, "a", 2, "b",3).ofType(Integer.class)
public XorM<W1,W2,T> filterNot(java.util.function.Predicate<? super T> predicate)
Filters
of(1,2,3).filter(i->i>2);
//[1,2]
public XorM<W1,W2,T> notNull()
Filters
of(1,2,null,4).nonNull();
//[1,2,4]
public <U> XorM<W1,W2,U> cast(java.lang.Class<? extends U> type)
TransformableClassCastException.
// ClassCastException ReactiveSeq.of(1, "a", 2, "b", 3).cast(Integer.class)cast in interface Transformable<T>public <R> XorM<W1,W2,R> map(java.util.function.Function<? super T,? extends R> fn)
Transformable
of(1,2,3).map(i->i*2)
//[2,4,6]
map in interface Transformable<T>fn - Transformation functionpublic XorM<W1,W2,T> peek(java.util.function.Consumer<? super T> c)
Transformable
of(1,2,3).map(System.out::println)
1
2
3
peek in interface Transformable<T>c - Consumer that recieves each element from this Transformablepublic java.lang.String toString()
toString in class java.lang.Objectpublic <R> XorM<W1,W2,R> trampoline(java.util.function.Function<? super T,? 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<T>mapper - TCO Transformation functionpublic <R> XorM<W1,W2,R> retry(java.util.function.Function<? super T,? 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<T>fn - Function to retry if failspublic <R> XorM<W1,W2,R> retry(java.util.function.Function<? super T,? 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<T>fn - Function to retry if failsretries - Number of retriesdelay - Delay in TimeUnitstimeUnit - TimeUnit to use for delaypublic ReactiveSeq<T> stream()
public XorM<W1,W2,T> zip(java.util.function.BinaryOperator<Zippable<T>> combiner, Zippable<T> app)
Zippablezip in interface Zippable<T>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));
}
public <R> XorM<W1,W2,R> zipWith(java.lang.Iterable<java.util.function.Function<? super T,? extends R>> fn)
public <R> XorM<W1,W2,R> zipWithS(java.util.stream.Stream<java.util.function.Function<? super T,? extends R>> fn)
public <R> XorM<W1,W2,R> zipWithP(org.reactivestreams.Publisher<java.util.function.Function<? super T,? extends R>> fn)
public <T2,R> XorM<W1,W2,R> zip(java.lang.Iterable<? extends T2> iterable, java.util.function.BiFunction<? super T,? super T2,? extends R> fn)
Zippablepublic <T2,R> XorM<W1,W2,R> zipP(org.reactivestreams.Publisher<? extends T2> publisher, java.util.function.BiFunction<? super T,? super T2,? extends R> fn)
Zippablepublic <U,R> XorM<W1,W2,R> zipS(java.util.stream.Stream<? extends U> other, java.util.function.BiFunction<? super T,? super U,? extends R> zipper)
Zippablepublic <U> XorM<W1,W2,org.jooq.lambda.tuple.Tuple2<T,U>> zipS(java.util.stream.Stream<? extends U> other)
Zippablepublic <U> XorM<W1,W2,org.jooq.lambda.tuple.Tuple2<T,U>> zipP(org.reactivestreams.Publisher<? extends U> other)
public <U> XorM<W1,W2,org.jooq.lambda.tuple.Tuple2<T,U>> zip(java.lang.Iterable<? extends U> other)
Zippablepublic <S,U> XorM<W1,W2,org.jooq.lambda.tuple.Tuple3<T,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']]
public <S,U,R> XorM<W1,W2,R> zip3(java.lang.Iterable<? extends S> second, java.lang.Iterable<? extends U> third, Fn3<? super T,? super S,? super U,? extends R> fn3)
public <T2,T3,T4> XorM<W1,W2,org.jooq.lambda.tuple.Tuple4<T,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"]]
public <T2,T3,T4,R> XorM<W1,W2,R> zip4(java.lang.Iterable<? extends T2> second, java.lang.Iterable<? extends T3> third, java.lang.Iterable<? extends T4> fourth, Fn4<? super T,? super T2,? super T3,? super T4,? extends R> fn)
public void subscribe(org.reactivestreams.Subscriber<? super T> s)
subscribe in interface org.reactivestreams.Publisher<T>public <R> R visit(java.util.function.Function<? super AnyM<W1,? super T>,? extends R> left, java.util.function.Function<? super AnyM<W2,? super T>,? extends R> right)
public java.util.Iterator<T> iterator()
iterator in interface java.lang.Iterable<T>public static <W1 extends WitnessType<W1>,T> XorM<W1,Witness.vectorX,T> vectorX(VectorX<T> list)
public static <W1 extends WitnessType<W1>,T> XorM<W1,Witness.vectorX,T> vectorX(T... values)
public static <W1 extends WitnessType<W1>,T> XorM<W1,Witness.linkedListX,T> linkedListX(LinkedListX<T> list)
public static <W1 extends WitnessType<W1>,T> XorM<W1,Witness.linkedListX,T> linkedListX(T... values)
public static <W1 extends WitnessType<W1>,T> XorM<W1,Witness.persistentSetX,T> persistentsetX(PersistentSetX<T> list)
public static <W1 extends WitnessType<W1>,T> XorM<W1,Witness.persistentSetX,T> persistentsetX(T... values)
public static <W1 extends WitnessType<W1>,T> XorM<W1,Witness.set,T> setX(java.util.Set<T> list)
public static <W1 extends WitnessType<W1>,T> XorM<W1,Witness.set,T> setX(T... values)
public static <W1 extends WitnessType<W1>,T> XorM<W1,Witness.list,T> listX(java.util.List<T> list)
public static <W1 extends WitnessType<W1>,T> XorM<W1,Witness.list,T> listX(T... values)
public static <W1 extends WitnessType<W1>,T> XorM<W1,Witness.stream,T> stream(java.util.stream.Stream<T> stream)
public static <W1 extends WitnessType<W1>,T> XorM<W1,Witness.stream,T> stream(T... values)
public static <W1 extends WitnessType<W1>,T> XorM<W1,Witness.reactiveSeq,T> reactiveSeq(ReactiveSeq<T> stream)
public static <W1 extends WitnessType<W1>,T> XorM<W1,Witness.reactiveSeq,T> reactiveSeq(T... values)
public static <W1 extends WitnessType<W1>,T> XorM<W1,Witness.tryType,T> success(T value)
public static <W1 extends WitnessType<W1>,X extends java.lang.Throwable,T> XorM<W1,Witness.tryType,T> failure(X value)
public static <W1 extends WitnessType<W1>,T> XorM<W1,Witness.future,T> futureOf(java.util.function.Supplier<T> value, java.util.concurrent.Executor ex)
public static <W1 extends WitnessType<W1>,T> XorM<W1,Witness.completableFuture,T> completableFutureOf(java.util.function.Supplier<T> value, java.util.concurrent.Executor ex)
public static <W1 extends WitnessType<W1>,T> XorM<W1,Witness.eval,T> later(java.util.function.Supplier<T> value)
public static <W1 extends WitnessType<W1>,T> XorM<W1,Witness.optional,T> ofNullable(T value)
public static <W1 extends WitnessType<W1>,T> XorM<W1,Witness.maybe,T> just(T value)
public static <W1 extends WitnessType<W1>,T> XorM<W1,Witness.maybe,T> none()
public static <W1 extends WitnessType<W1>,T> XorM<W1,Witness.maybe,T> maybeNullabe(T value)