F
- public interface FeatureToggle<F> extends java.util.function.Supplier<F>, MonadicValue<F>, Filterable<F>, Functor<F>, ApplicativeFunctor<F>, Matchable.ValueAndOptionalMatcher<F>
Modifier and Type | Interface and Description |
---|---|
static class |
FeatureToggle.Disabled<F>
An disabled switch
|
static class |
FeatureToggle.Enabled<F>
An enabled switch
|
ApplicativeFunctor.Applicatives, ApplicativeFunctor.ApplyFunctions<T>
Value.ValueImpl<T>
Convertable.SupplierToConvertable<T>
Modifier and Type | Method and Description |
---|---|
AnyMValue<F> |
anyM() |
AnyM<F> |
anyMDisabled() |
AnyM<F> |
anyMEnabled() |
default <T2,R> FeatureToggle<R> |
ap(Value<? extends T2> app,
java.util.function.BiFunction<? super F,? super T2,? extends R> fn)
Apply a function across to values at once.
|
default <U> FeatureToggle<U> |
cast(java.lang.Class<? extends U> type)
Cast all elements in a stream to a given type, possibly throwing a
ClassCastException . |
default FeatureToggle.Disabled<F> |
disable() |
static <F> FeatureToggle.Disabled<F> |
disable(F f)
Create a new disabled switch
|
default FeatureToggle.Enabled<F> |
enable() |
static <F> FeatureToggle.Enabled<F> |
enable(F f)
Create a new enabled switch
|
default FeatureToggle<F> |
filter(java.util.function.Predicate<? super F> p)
Filter this Switch.
|
default FeatureToggle<F> |
filterNot(java.util.function.Predicate<? super F> fn)
Remove any elements for which the predicate holds (inverse operation to filter)
e.g.
|
default <X> FeatureToggle<X> |
flatMap(java.util.function.Function<? super F,? extends MonadicValue<? extends X>> map) |
default FeatureToggle<F> |
flip() |
default void |
forEach(java.util.function.Consumer<? super F> consumer)
Iterate over value in switch (single value, so one iteration)
|
static <F> FeatureToggle<F> |
from(FeatureToggle<F> from,
F f) |
F |
get() |
boolean |
isDisabled() |
boolean |
isEnabled() |
default java.util.Iterator<F> |
iterator() |
default <X> FeatureToggle<X> |
map(java.util.function.Function<? super F,? extends X> map)
Transform this functor using the supplied transformation function
|
static <T> FeatureToggle<T> |
narrow(FeatureToggle<? extends T> toggle) |
default FeatureToggle<F> |
notNull()
Filter elements retaining only values which are not null
|
default <U> FeatureToggle<U> |
ofType(java.lang.Class<? extends U> type)
Keep only those elements in a stream that are of a given type.
|
default java.util.Optional<F> |
optional() |
default <R> FeatureToggle<R> |
patternMatch(java.util.function.Function<Matchable.CheckValue1<F,R>,Matchable.CheckValue1<F,R>> case1,
java.util.function.Supplier<? extends R> otherwise)
Transform the elements of this Stream with a Pattern Matching case and default value
|
default FeatureToggle<F> |
peek(java.util.function.Consumer<? super F> consumer)
Peek at current switch value
|
default ReactiveSeq<F> |
stream() |
default FeatureToggle<F> |
toFeatureToggle() |
default <R> FeatureToggle<R> |
trampoline(java.util.function.Function<? super F,? extends Trampoline<? extends R>> mapper)
Performs a map operation that can call a recursive method without running out of stack space
|
default <T> FeatureToggle<T> |
unit(T unit) |
<R> R |
visit(java.util.function.Function<? super F,? extends R> enabled,
java.util.function.Function<? super F,? extends R> disabled) |
default <T2,R> FeatureToggle<R> |
zip(java.util.function.BiFunction<? super F,? super T2,? extends R> fn,
org.reactivestreams.Publisher<? extends T2> app)
Equivalent to ap, but accepts a Publisher and takes the first value only from that publisher.
|
default <T2,R> FeatureToggle<R> |
zip(java.lang.Iterable<? extends T2> app,
java.util.function.BiFunction<? super F,? super T2,? extends R> fn)
Equivalent to ap, but accepts an Iterable and takes the first value only from that iterable.
|
coflatMap, nest
applyFunctions
collect, fold, fold, generate, iterate, mapReduce, mkString, newSubscriber, of, subscribe, test, toDequeX, toEvalAlways, toEvalLater, toEvalNow, toFutureStream, toFutureStream, toIor, toLazyImmutable, toList, toListX, toMaybe, toMutable, toPBagX, toPOrderedSetX, toPQueueX, toPSetX, toPStackX, toPVectorX, toQueueX, toSetX, toSimpleReact, toSimpleReact, toSortedSetX, toTry, toTry, toTry, toXor, toXor, unapply
endsWith, 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, xMatch
collect, fromSupplier, isPresent, orElse, orElseGet, orElseThrow, toAtomicReference, toCompletableFuture, toCompletableFutureAsync, toCompletableFutureAsync, toFutureW, toFutureWAsync, toFutureWAsync, toOptional, toOptionalAtomicReference, toStream, visit
toOptional, visit
matches
boolean isEnabled()
boolean isDisabled()
static <T> FeatureToggle<T> narrow(FeatureToggle<? extends T> toggle)
default <U> FeatureToggle<U> cast(java.lang.Class<? extends U> type)
Functor
ClassCastException
.
// ClassCastException ReactiveSeq.of(1, "a", 2, "b", 3).cast(Integer.class)default <R> FeatureToggle<R> trampoline(java.util.function.Function<? super F,? 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<F>
default <U> FeatureToggle<U> ofType(java.lang.Class<? extends U> type)
Filterable
// (1, 2, 3) ReactiveSeq.of(1, "a", 2, "b",3).ofType(Integer.class)
ofType
in interface Filterable<F>
default FeatureToggle<F> filterNot(java.util.function.Predicate<? super F> fn)
Filterable
of(1,2,3).filter(i->i>2);
//[1,2]
filterNot
in interface Filterable<F>
fn
- to filter elements by, retaining matchesdefault FeatureToggle<F> notNull()
Filterable
of(1,2,null,4).nonNull();
//[1,2,4]
notNull
in interface Filterable<F>
default <T> FeatureToggle<T> unit(T unit)
<R> R visit(java.util.function.Function<? super F,? extends R> enabled, java.util.function.Function<? super F,? extends R> disabled)
default <R> FeatureToggle<R> patternMatch(java.util.function.Function<Matchable.CheckValue1<F,R>,Matchable.CheckValue1<F,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<F>
case1
- Function to generate a case (or chain of cases as a single case)otherwise
- Value if supplied case doesn't matchdefault FeatureToggle<F> toFeatureToggle()
toFeatureToggle
in interface Value<F>
AnyMValue<F> anyM()
anyM
in interface MonadicValue<F>
F get()
get
in interface Convertable<F>
get
in interface java.util.function.Supplier<F>
static <F> FeatureToggle.Enabled<F> enable(F f)
f
- switch valuestatic <F> FeatureToggle.Disabled<F> disable(F f)
f
- switch valuestatic <F> FeatureToggle<F> from(FeatureToggle<F> from, F f)
from
- Create a switch with the same typef
- but with this value (f)default FeatureToggle<F> peek(java.util.function.Consumer<? super F> consumer)
default <X> FeatureToggle<X> flatMap(java.util.function.Function<? super F,? extends MonadicValue<? extends X>> map)
map
- Create a new Switch with provided functiondefault <X> FeatureToggle<X> map(java.util.function.Function<? super F,? extends X> map)
Functor
of(1,2,3).map(i->i*2)
//[2,4,6]
map
in interface ConvertableFunctor<F>
map
in interface Functor<F>
map
in interface MonadicValue<F>
map
- transform the value inside this Switch into new Switch objectdefault FeatureToggle<F> filter(java.util.function.Predicate<? super F> p)
filter
in interface Filterable<F>
p
- Predicate to test fordefault void forEach(java.util.function.Consumer<? super F> consumer)
forEach
in interface java.lang.Iterable<F>
consumer
- to provide value to.default FeatureToggle.Enabled<F> enable()
default FeatureToggle.Disabled<F> disable()
default FeatureToggle<F> flip()
default java.util.Optional<F> optional()
default ReactiveSeq<F> stream()
default java.util.Iterator<F> iterator()
iterator
in interface Convertable<F>
iterator
in interface java.lang.Iterable<F>
iterator
in interface Matchable.MatchableOptional<F>
iterator
in interface Matchable.ValueAndOptionalMatcher<F>
default <T2,R> FeatureToggle<R> ap(Value<? extends T2> app, java.util.function.BiFunction<? super F,? super T2,? extends R> fn)
ap
in interface ApplicativeFunctor<F>
app
- fn
- default <T2,R> FeatureToggle<R> zip(java.lang.Iterable<? extends T2> app, java.util.function.BiFunction<? super F,? super T2,? extends R> fn)
zip
in interface ApplicativeFunctor<F>
app
- fn
- default <T2,R> FeatureToggle<R> zip(java.util.function.BiFunction<? super F,? super T2,? extends R> fn, org.reactivestreams.Publisher<? extends T2> app)
zip
in interface ApplicativeFunctor<F>
app
- fn
-