T - The type contained on the Xor withinpublic class XorTValue<ST,T> extends java.lang.Object implements XorT<ST,T>, MonadicValue2<ST,T>, TransformerValue<T>, java.util.function.Supplier<T>, ConvertableFunctor<T>, Filterable<T>, Applicativable<T>, Matchable.ValueAndOptionalMatcher<T>
Applicativable.Applicatives, Applicativable.SemigroupApplyer<T>Value.ValueImpl<T>Convertable.SupplierToConvertable<T>| Modifier and Type | Method and Description |
|---|---|
<U> XorTValue<ST,U> |
cast(java.lang.Class<? extends U> type)
Cast all elements in a stream to a given type, possibly throwing a
ClassCastException. |
<R> XorTValue<ST,R> |
empty() |
static <ST,PT> XorTValue<ST,PT> |
emptyOptional() |
XorTValue<ST,T> |
filter(java.util.function.Predicate<? super T> test)
Filter the wrapped Xor
|
XorTValue<ST,T> |
filterNot(java.util.function.Predicate<? super T> fn)
Remove any elements for which the predicate holds (inverse operation to filter)
e.g.
|
<ST2,B> XorTValue<ST2,B> |
flatMap(java.util.function.Function<? super T,? extends MonadicValue2<? extends ST2,? extends B>> f) |
<ST2,B> XorTValue<ST,B> |
flatMapT(java.util.function.Function<? super T,XorTValue<ST2,? extends B>> f)
Flat Map the wrapped Xor
|
static <ST,A> XorTValue<ST,A> |
fromAnyM(AnyMValue<A> anyM)
|
static <A,ST,V extends MonadicValue<Xor<ST,A>>> |
fromValue(V monadicValue) |
T |
get() |
boolean |
isPrimary() |
boolean |
isSecondary() |
boolean |
isValuePresent() |
java.util.Iterator<T> |
iterator() |
static <ST,U,R> java.util.function.Function<XorTValue<ST,U>,XorTValue<ST,R>> |
lift(java.util.function.Function<? super U,? extends R> fn)
Lift a function into one that accepts and returns an XorT This allows
multiple monad types to add functionality to existing functions and
methods
e.g.
|
static <ST,U1,U2,R> |
lift2(java.util.function.BiFunction<? super U1,? super U2,? extends R> fn)
Lift a BiFunction into one that accepts and returns XorTs This allows
multiple monad types to add functionality to existing functions and
methods
e.g.
|
<B> XorTValue<ST,B> |
map(java.util.function.Function<? super T,? extends B> f)
Map the wrapped Xor
|
XorTValue<ST,T> |
notNull()
Filter elements retaining only values which are not null
|
static <ST,A> XorTValue<ST,A> |
of(AnyMValue<Xor<ST,A>> monads)
Construct an XorT from an AnyM that wraps a monad containing Xors
|
static <ST,A> XorTValue<ST,A> |
of(Xor<ST,A> monads) |
<U> XorTValue<ST,U> |
ofType(java.lang.Class<? extends U> type)
Keep only those elements in a stream that are of a given type.
|
<R> XorTValue<ST,R> |
patternMatch(java.util.function.Function<Matchable.CheckValue1<T,R>,Matchable.CheckValue1<T,R>> case1,
java.util.function.Supplier<? extends R> otherwise)
Transform the elements of this Stream with a Pattern Matching case and default value
|
XorTValue<ST,T> |
peek(java.util.function.Consumer<? super T> peek)
Peek at the current value of the Xor
|
ReactiveSeq<T> |
stream() |
void |
subscribe(org.reactivestreams.Subscriber<? super T> s) |
XorTValue<T,ST> |
swap() |
boolean |
test(T t) |
java.lang.String |
toString() |
<R> XorTValue<ST,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
|
<R> XorTValue<ST,R> |
unit(R value) |
AnyMValue<Xor<ST,T>> |
unwrap() |
Xor<ST,T> |
value() |
<R> R |
visit(java.util.function.Function<?,? extends R> secondary,
java.util.function.Function<? super T,? extends R> primary,
java.util.function.Supplier<R> none) |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitbind, emptyList, fromAnyM, fromAnyMSeq, fromAnyMValue, fromFuture, fromIterable, fromIterablXorue, fromOptional, fromPublisher, fromStream, ofcombineanyM, coflatMap, isPresent, nestap, ap, ap1, ap2, ap3, ap4, ap5fold, fold, generate, iterate, mapReduce, mkString, newSubscriber, of, toDequeX, toEvalAlways, toEvalLater, toEvalNow, toFeatureToggle, toFutureStream, toFutureStream, toIor, toLazyImmutable, toListX, toMaybe, toMutable, toPBagX, toPOrderedSetX, toPQueueX, toPSetX, toPStackX, toPVectorX, toQueueX, toSetX, toSimpleReact, toSimpleReact, toSortedSetX, toTry, toTry, toTry, toXor, toXor, unapply, visitendsWith, endsWithIterable, findAny, findFirst, firstValue, foldable, foldRight, foldRight, foldRight, foldRightMapToType, get, groupBy, headAndTail, 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, visit, visit, xMatchfromSupplier, orElse, orElseGet, orElseThrow, toAtomicReference, toCompletableFuture, toCompletableFutureAsync, toCompletableFutureAsync, toFutureW, toList, toOptional, toOptionalAtomicReference, toStreamtoOptional, visitmatchespublic boolean isValuePresent()
isValuePresent in interface TransformerValue<T>public XorTValue<ST,T> peek(java.util.function.Consumer<? super T> peek)
XorT.of(AnyM.fromStream(Xor.of(10))
.peek(System.out::println);
//prints 10
public XorTValue<ST,T> filter(java.util.function.Predicate<? super T> test)
XorT.of(AnyM.fromStream(Xor.of(10))
.filter(t->t!=10);
//XorT<AnyMValue<Stream<Xor.empty>>>
filter in interface TransformerValue<T>filter in interface XorT<ST,T>filter in interface Filterable<T>test - Predicate to filter the wrapped Xorpublic <B> XorTValue<ST,B> map(java.util.function.Function<? super T,? extends B> f)
XorT.of(AnyM.fromStream(Xor.of(10))
.map(t->t=t+1);
//XorT<AnyMValue<Stream<Xor[11]>>>
map in interface TransformerValue<T>map in interface XorT<ST,T>map in interface ConvertableFunctor<T>map in interface Functor<T>map in interface MonadicValue<T>map in interface MonadicValue2<ST,T>f - Mapping function for the wrapped Xorpublic <ST2,B> XorTValue<ST,B> flatMapT(java.util.function.Function<? super T,XorTValue<ST2,? extends B>> f)
XorT.of(AnyM.fromStream(Xor.of(10))
.flatMap(t->Xor.empty();
//XorT<AnyMValue<Stream<Xor.empty>>>
f - FlatMap functionpublic <ST2,B> XorTValue<ST2,B> flatMap(java.util.function.Function<? super T,? extends MonadicValue2<? extends ST2,? extends B>> f)
public static <ST,U,R> java.util.function.Function<XorTValue<ST,U>,XorTValue<ST,R>> lift(java.util.function.Function<? super U,? extends R> fn)
{
@code
Function add2 = i -> i + 2;
Function, XorT> optTAdd2 = XorT.lift(add2);
Stream withNulls = Stream.of(1, 2, null);
AnyMValue stream = AnyM.ofMonad(withNulls);
AnyMValue> streamOpt = stream.map(Xor::ofNullable);
List results = optTAdd2.apply(XorT.of(streamOpt)).unwrap().>> unwrap()
.filter(Xor::isPresent).map(Xor::get).collect(Collectors.toList());
// Arrays.asList(3,4);
}
public static <ST,U1,U2,R> java.util.function.BiFunction<XorTValue<ST,U1>,XorTValue<ST,U2>,XorTValue<ST,R>> lift2(java.util.function.BiFunction<? super U1,? super U2,? extends R> fn)
{
@code
BiFunction add = (a, b) -> a + b;
BiFunction, XorT, XorT> optTAdd2 = XorT.lift2(add);
Stream withNulls = Stream.of(1, 2, null);
AnyMValue stream = AnyM.ofMonad(withNulls);
AnyMValue> streamOpt = stream.map(Xor::ofNullable);
CompletableFuture> two = CompletableFuture.supplyAsync(() -> Xor.of(2));
AnyMValue> future = AnyM.ofMonad(two);
List results = optTAdd2.apply(XorT.of(streamOpt), XorT.of(future)).unwrap()
.>> unwrap().filter(Xor::isPresent).map(Xor::get)
.collect(Collectors.toList());
// Arrays.asList(3,4);
}
public static <ST,A> XorTValue<ST,A> fromAnyM(AnyMValue<A> anyM)
anyM - AnyM that doesn't contain a monad wrapping an Xorpublic static <ST,A> XorTValue<ST,A> of(AnyMValue<Xor<ST,A>> monads)
monads - AnyM that contains a monad wrapping an Xorpublic static <A,ST,V extends MonadicValue<Xor<ST,A>>> XorTValue<ST,A> fromValue(V monadicValue)
public java.lang.String toString()
toString in class java.lang.Objectpublic T get()
get in interface Convertable<T>get in interface java.util.function.Supplier<T>public boolean isPrimary()
public boolean isSecondary()
public ReactiveSeq<T> stream()
public java.util.Iterator<T> iterator()
iterator in interface Matchable.MatchableOptional<T>iterator in interface Matchable.ValueAndOptionalMatcher<T>iterator in interface Convertable<T>iterator in interface java.lang.Iterable<T>public void subscribe(org.reactivestreams.Subscriber<? super T> s)
public boolean test(T t)
public <R> R visit(java.util.function.Function<?,? extends R> secondary,
java.util.function.Function<? super T,? extends R> primary,
java.util.function.Supplier<R> none)
public static <ST,PT> XorTValue<ST,PT> emptyOptional()
emptyOptional in interface XorT<ST,T>public <U> XorTValue<ST,U> cast(java.lang.Class<? extends U> type)
FunctorClassCastException.
// ClassCastException ReactiveSeq.of(1, "a", 2, "b", 3).cast(Integer.class)public <R> XorTValue<ST,R> trampoline(java.util.function.Function<? super T,? 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 TransformerValue<T>trampoline in interface XorT<ST,T>trampoline in interface Functor<T>public <R> XorTValue<ST,R> patternMatch(java.util.function.Function<Matchable.CheckValue1<T,R>,Matchable.CheckValue1<T,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 TransformerValue<T>patternMatch in interface XorT<ST,T>patternMatch in interface Functor<T>case1 - Function to generate a case (or chain of cases as a single case)otherwise - Value if supplied case doesn't matchpublic <U> XorTValue<ST,U> ofType(java.lang.Class<? extends U> type)
Filterable
// (1, 2, 3) ReactiveSeq.of(1, "a", 2, "b",3).ofType(Integer.class)
public XorTValue<ST,T> filterNot(java.util.function.Predicate<? super T> fn)
Filterable
of(1,2,3).filter(i->i>2);
//[1,2]
public XorTValue<ST,T> notNull()
Filterable
of(1,2,null,4).nonNull();
//[1,2,4]