T - The type contained on the Try withinpublic class TryTValue<T,X extends java.lang.Throwable> extends java.lang.Object implements TryT<T,X>, TransformerValue<T>, MonadicValue<T>, java.util.function.Supplier<T>, ConvertableFunctor<T>, Filterable<T>, ApplicativeFunctor<T>, Matchable.ValueAndOptionalMatcher<T>
ApplicativeFunctor.Applicatives, ApplicativeFunctor.ApplyFunctions<T>Value.ValueImpl<T>Convertable.SupplierToConvertable<T>| Modifier and Type | Method and Description |
|---|---|
<T2,R> TryTValue<R,X> |
ap(Value<? extends T2> app,
java.util.function.BiFunction<? super T,? super T2,? extends R> fn) |
<U> TryTValue<U,X> |
cast(java.lang.Class<? extends U> type)
Cast all elements in a stream to a given type, possibly throwing a
ClassCastException. |
<R> TryTValue<R,X> |
empty() |
static <T,X extends java.lang.Throwable> |
emptyOptional() |
boolean |
equals(java.lang.Object o) |
MaybeTValue<T> |
filter(java.util.function.Predicate<? super T> test)
Filter the wrapped Try
|
MaybeTValue<T> |
filterNot(java.util.function.Predicate<? super T> fn)
Remove any elements for which the predicate holds (inverse operation to filter)
e.g.
|
<B> TryTValue<B,X> |
flatMap(java.util.function.Function<? super T,? extends Try<B,X>> f) |
<B> TryTValue<B,X> |
flatMapT(java.util.function.Function<? super T,TryTValue<B,X>> f)
Flat Map the wrapped Try
|
static <A,X extends java.lang.Throwable> |
fromAnyM(AnyMValue<A> anyM)
|
static <A,X extends java.lang.Throwable,V extends MonadicValue<Try<A,X>>> |
fromValue(V monadicValue) |
T |
get() |
int |
hashCode() |
boolean |
isFailure() |
boolean |
isSuccess() |
boolean |
isValuePresent() |
java.util.Iterator<T> |
iterator() |
static <U,R,X extends java.lang.Throwable> |
lift(java.util.function.Function<? super U,? extends R> fn)
Lift a function into one that accepts and returns an TryT
This allows multiple monad types to add functionality to existing functions and methods
e.g.
|
static <U1,U2,R,X extends java.lang.Throwable> |
lift2(java.util.function.BiFunction<? super U1,? super U2,? extends R> fn)
Lift a BiFunction into one that accepts and returns TryTs
This allows multiple monad types to add functionality to existing functions and methods
e.g.
|
<B> TryTValue<B,X> |
map(java.util.function.Function<? super T,? extends B> f)
Map the wrapped Try
|
MaybeTValue<T> |
notNull()
Filter elements retaining only values which are not null
|
static <A,X extends java.lang.Throwable> |
of(AnyMValue<Try<A,X>> monads)
Construct an TryT from an AnyM that wraps a monad containing Trys
|
static <A,X extends java.lang.Throwable> |
of(Try<A,X> monads) |
<U> MaybeTValue<U> |
ofType(java.lang.Class<? extends U> type)
Keep only those elements in a stream that are of a given type.
|
<R> TryTValue<R,X> |
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
|
TryTValue<T,X> |
peek(java.util.function.Consumer<? super T> peek)
Peek at the current value of the Try
|
ReactiveSeq<T> |
stream() |
void |
subscribe(org.reactivestreams.Subscriber<? super T> s) |
boolean |
test(T t) |
java.lang.String |
toString() |
<R> TryTValue<R,X> |
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> TryTValue<R,X> |
unit(R value) |
AnyMValue<Try<T,X>> |
unwrap() |
Try<T,X> |
value() |
<R> R |
visit(java.util.function.Function<? super T,? extends R> success,
java.util.function.Function<? super X,? extends R> failure,
java.util.function.Supplier<R> none) |
<T2,R> TryTValue<R,X> |
zip(java.util.function.BiFunction<? super T,? super T2,? extends R> fn,
org.reactivestreams.Publisher<? extends T2> app) |
<T2,R> TryTValue<R,X> |
zip(java.lang.Iterable<? extends T2> app,
java.util.function.BiFunction<? super T,? super T2,? extends R> fn) |
clone, finalize, getClass, notify, notifyAll, wait, wait, waitbind, emptyList, fromAnyM, fromAnyMSeq, fromAnyMValue, fromFuture, fromIterable, fromIterablTryue, fromOptional, fromPublisher, fromStream, ofisPresentanyM, coflatMap, nestapplyFunctionscollect, fold, fold, generate, iterate, mapReduce, mkString, newSubscriber, of, toDequeX, toEvalAlways, toEvalLater, toEvalNow, toFeatureToggle, toFutureStream, toFutureStream, toIor, toLazyImmutable, toList, toListX, toMaybe, toMutable, toPBagX, toPOrderedSetX, toPQueueX, toPSetX, toPStackX, toPVectorX, toQueueX, toSetX, toSimpleReact, toSimpleReact, toSortedSetX, toTry, toTry, toTry, toXor, toXor, unapplyendsWith, 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, xMatchcollect, fromSupplier, orElse, orElseGet, orElseThrow, toAtomicReference, toCompletableFuture, toCompletableFutureAsync, toCompletableFutureAsync, toFutureW, toFutureWAsync, toFutureWAsync, toOptional, toOptionalAtomicReference, toStream, visittoOptional, visitmatchespublic boolean isValuePresent()
isValuePresent in interface TransformerValue<T>public TryTValue<T,X> peek(java.util.function.Consumer<? super T> peek)
TryT.of(AnyM.fromStream(Try.success(10))
.peek(System.out::println);
//prints 10
public MaybeTValue<T> filter(java.util.function.Predicate<? super T> test)
TryT.of(AnyM.fromStream(Try.success(10))
.filter(t->t!=10);
//TryT<AnyMValue<Stream<Optional.empty>>>
filter in interface TryT<T,X extends java.lang.Throwable>filter in interface TransformerValue<T>filter in interface Filterable<T>test - Predicate to filter the wrapped Trypublic <B> TryTValue<B,X> map(java.util.function.Function<? super T,? extends B> f)
TryT.of(AnyM.fromStream(Try.success(10))
.map(t->t=t+1);
//TryT<AnyMValue<Stream<Success[11]>>>
map in interface TryT<T,X extends java.lang.Throwable>map in interface TransformerValue<T>map in interface ConvertableFunctor<T>map in interface Functor<T>map in interface MonadicValue<T>f - Mapping function for the wrapped Trypublic <T2,R> TryTValue<R,X> ap(Value<? extends T2> app, java.util.function.BiFunction<? super T,? super T2,? extends R> fn)
ap in interface ApplicativeFunctor<T>public <T2,R> TryTValue<R,X> zip(java.lang.Iterable<? extends T2> app, java.util.function.BiFunction<? super T,? super T2,? extends R> fn)
zip in interface ApplicativeFunctor<T>public <T2,R> TryTValue<R,X> zip(java.util.function.BiFunction<? super T,? super T2,? extends R> fn, org.reactivestreams.Publisher<? extends T2> app)
zip in interface ApplicativeFunctor<T>public <B> TryTValue<B,X> flatMapT(java.util.function.Function<? super T,TryTValue<B,X>> f)
TryT.of(AnyM.fromStream(Try.success(10))
.flatMap(t->Try.failure(new Exception());
//TryT<AnyMValue<Stream<Failure[Excption]>>>
f - FlatMap functionpublic <B> TryTValue<B,X> flatMap(java.util.function.Function<? super T,? extends Try<B,X>> f)
public static <U,R,X extends java.lang.Throwable> java.util.function.Function<TryTValue<U,X>,TryTValue<R,X>> lift(java.util.function.Function<? super U,? extends R> fn)
Function<Integer,Integer> add2 = i -> i+2;
Function<TryT<Integer,RuntimeException>, TryT<Integer,RuntimeException>> optTAdd2 = TryT.lift(add2);
Stream<Integer> withNulls = Stream.of(1,2,null);
AnyMValue<Integer> stream = AnyM.ofMonad(withNulls);
AnyMValue<Try<Integer,RuntimeException>> streamOpt = stream.map(this::toTry);
List<Integer> results = optTAdd2.apply(TryT.of(streamOpt))
.unwrap()
.<Stream<Try<Integer,RuntimeException>>>unwrap()
.filter(Try::isSuccess)
.map(Try::get)
.collect(Collectors.toList());
//Arrays.asList(3,4);
public static <U1,U2,R,X extends java.lang.Throwable> java.util.function.BiFunction<TryTValue<U1,X>,TryTValue<U2,X>,TryTValue<R,X>> lift2(java.util.function.BiFunction<? super U1,? super U2,? extends R> fn)
BiFunction<Integer,Integer,Integer> add = (a,b) -> a+b;
BiFunction<TryT<Integer,RuntimeException>,TryT<Integer,RuntimeException>, TryT<Integer,RuntimeException>> optTAdd2 = TryT.lift2(add);
Stream<Integer> withNulls = Stream.of(1,2,null);
AnyMValue<Integer> stream = AnyM.ofMonad(withNulls);
AnyMValue<Try<Integer,RuntimeException>> streamOpt = stream.map(this::toTry);
CompletableFuture<Try<Integer,RuntimeException>> two = CompletableFuture.completedFuture(Try.of(2));
AnyMValue<Try<Integer,RuntimeException>> future= AnyM.ofMonad(two);
List<Integer> results = optTAdd2.apply(TryT.of(streamOpt),TryT.of(future))
.unwrap()
.<Stream<Try<Integer,RuntimeException>>>unwrap()
.filter(Try::isSuccess)
.map(Try::get)
.collect(Collectors.toList());
//Arrays.asList(3,4);
public static <A,X extends java.lang.Throwable> TryTValue<A,X> fromAnyM(AnyMValue<A> anyM)
anyM - AnyM that doesn't contain a monad wrapping an Trypublic static <A,X extends java.lang.Throwable> TryTValue<A,X> of(AnyMValue<Try<A,X>> monads)
monads - AnyM that contains a monad wrapping an Trypublic static <A,X extends java.lang.Throwable,V extends MonadicValue<Try<A,X>>> TryTValue<A,X> 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 isSuccess()
public boolean isFailure()
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<? super T,? extends R> success, java.util.function.Function<? super X,? extends R> failure, java.util.function.Supplier<R> none)
public static <T,X extends java.lang.Throwable> TryTValue<T,X> emptyOptional()
emptyOptional in interface TryT<T,X extends java.lang.Throwable>public <U> TryTValue<U,X> cast(java.lang.Class<? extends U> type)
FunctorClassCastException.
// ClassCastException ReactiveSeq.of(1, "a", 2, "b", 3).cast(Integer.class)public <R> TryTValue<R,X> 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 TryT<T,X extends java.lang.Throwable>trampoline in interface TransformerValue<T>trampoline in interface Functor<T>public <R> TryTValue<R,X> 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 TryT<T,X extends java.lang.Throwable>patternMatch in interface TransformerValue<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> MaybeTValue<U> ofType(java.lang.Class<? extends U> type)
Filterable
// (1, 2, 3) ReactiveSeq.of(1, "a", 2, "b",3).ofType(Integer.class)
public MaybeTValue<T> filterNot(java.util.function.Predicate<? super T> fn)
Filterable
of(1,2,3).filter(i->i>2);
//[1,2]
public MaybeTValue<T> notNull()
Filterable
of(1,2,null,4).nonNull();
//[1,2,4]
public int hashCode()
hashCode in class java.lang.Objectpublic boolean equals(java.lang.Object o)
equals in class java.lang.Object