public interface TransformerValue<T> extends MonadicValue<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 |
---|---|
default <U> TransformerValue<U> |
cast(java.lang.Class<? extends U> type)
Cast all elements in a stream to a given type, possibly throwing a
ClassCastException . |
TransformerValue<T> |
filter(java.util.function.Predicate<? super T> fn)
Keep only elements for which the supplied predicates hold
e.g.
|
boolean |
isValuePresent() |
<R> TransformerValue<R> |
map(java.util.function.Function<? super T,? extends R> fn)
Transform this functor using the supplied transformation function
|
default <R> TransformerValue<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
|
default TransformerValue<T> |
peek(java.util.function.Consumer<? super T> c)
Peek at the current value of this Functor, without transforming it
|
default <R> TransformerValue<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
|
<T> TransformerValue<T> |
unit(T unit) |
MonadicValue<T> |
value() |
anyM, coflatMap, isPresent, nest
filterNot, notNull, ofType
ap, ap, ap1, ap2, ap3, ap4, ap5
fold, fold, generate, iterate, mapReduce, mkString, newSubscriber, of, stream, subscribe, test, 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, visit
endsWith, 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, xMatch
fromSupplier, get, iterator, orElse, orElseGet, orElseThrow, toAtomicReference, toCompletableFuture, toCompletableFutureAsync, toCompletableFutureAsync, toFutureW, toList, toOptional, toOptionalAtomicReference, toStream
iterator, toOptional, visit
matches
boolean isValuePresent()
MonadicValue<T> value()
TransformerValue<T> filter(java.util.function.Predicate<? super T> fn)
Filterable
of(1,2,3).filter(i->i>2);
//[3]
filter
in interface Filterable<T>
fn
- to filter elements by, retaining matches<T> TransformerValue<T> unit(T unit)
<R> TransformerValue<R> map(java.util.function.Function<? super T,? extends R> fn)
Functor
of(1,2,3).map(i->i*2)
//[2,4,6]
map
in interface ConvertableFunctor<T>
map
in interface Functor<T>
map
in interface MonadicValue<T>
fn
- Transformation functiondefault <U> TransformerValue<U> cast(java.lang.Class<? extends U> type)
Functor
ClassCastException
.
// ClassCastException ReactiveSeq.of(1, "a", 2, "b", 3).cast(Integer.class)default TransformerValue<T> peek(java.util.function.Consumer<? super T> c)
Functor
of(1,2,3).map(System.out::println)
1
2
3
default <R> TransformerValue<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 Functor<T>
default <R> TransformerValue<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 Functor<T>
case1
- Function to generate a case (or chain of cases as a single case)otherwise
- Value if supplied case doesn't match