W1
- First Witness type Witness
W2
- Second Witness type Witness
T
- Nested Data Typepublic class Nested<W1,W2,T> extends java.lang.Object implements Transformable<T>, Higher3<Witness.nested,W1,W2,T>, To<Nested<W1,W2,T>>
import cyclops.monads.Witness.list;
import cyclops.monads.Witness.optional;
Nested<list,optional,Integer> listOfOptionalInt = Nested.of(ListX.of(Optionals.OptionalKind.of(2)),ListX.Instances.definitions(),Optionals.Instances.definitions());
//Nested[List[Optional[2]]]
Transform nest data
Nested<list,optional,Integer> listOfOptionalInt; //Nested[List[Optional[2]]]
Nested<list,optional,Integer> doubled = listOfOptionalInt.map(i->i*2);
//Nested[List[Optional[4]]]
Sequencing data
Nested<list,optional,Integer> listOfOptionalInt; //Nested[List[Optional[2]]]
Nested<optional,list,Integer> sequenced = listOfOptionalInt.sequence();
//Nested[Optional[List[2]]]
Modifier and Type | Class and Description |
---|---|
static interface |
Nested.Converter<W,S> |
static class |
Nested.Instances |
static class |
Nested.NestedComprehensions<W1,W2,T> |
class |
Nested.Plus |
class |
Nested.Unfolds |
Modifier and Type | Field and Description |
---|---|
InstanceDefinitions<W1> |
def1 |
InstanceDefinitions<W2> |
def2 |
Higher<W1,Higher<W2,T>> |
nested |
Constructor and Description |
---|
Nested() |
Modifier and Type | Method and Description |
---|---|
Active<Higher<Higher<Witness.nested,W1>,W2>,T> |
allTypeclasses(TransformerFactory<W1,W2> factory) |
<R> Nested<W1,W2,R> |
ap(Higher<W2,? extends java.util.function.Function<T,R>> fn) |
<U> Nested<W1,W2,U> |
cast(java.lang.Class<? extends U> type)
Cast all elements in a reactiveStream to a given type, possibly throwing a
ClassCastException . |
static <T> Nested<Witness.completableFuture,Witness.stream,T> |
completableFutureStream(java.util.concurrent.CompletableFuture<? extends java.util.stream.Stream<T>> optionalList) |
Nested.NestedComprehensions<W1,W2,T> |
comprehensions(TransformerFactory<W1,W2> factory) |
Maybe<Nested.NestedComprehensions.Guarded<W1,W2,T>> |
comprehensionsGuarded(TransformerFactory<W1,W2> factory) |
Maybe<Comprehensions.Guarded<Higher<Higher<Witness.nested,W1>,W2>>> |
comprehensionsGuardedHk(TransformerFactory<W1,W2> factory) |
Comprehensions<Higher<Higher<Witness.nested,W1>,W2>> |
comprehensionsHk(TransformerFactory<W1,W2> factory) |
<C,R> cyclops.typeclasses.Nested.NarrowedApplicative<C,R> |
concreteAp(Kleisli<W2,C,java.util.function.Function<T,R>> widen) |
<S,R> Nested.Converter<W1,S> |
concreteConversion(java.util.function.Function<? super Higher<W2,T>,? extends S> narrow2) |
<C,R> cyclops.typeclasses.Nested.NarrowedFlatMap<C,R> |
concreteFlatMap(Kleisli<W2,C,R> widen) |
<C> cyclops.typeclasses.Nested.Narrowed<C> |
concreteMonoid(Kleisli<W2,C,T> widen,
Cokleisli<W2,T,C> narrow) |
<C,R> cyclops.typeclasses.Nested.NarrowedTailRec<C,R> |
concreteTailRec(Kleisli<W2,C,Xor<T,R>> widen) |
InstanceDefinitions<Higher<Higher<Witness.nested,W1>,W2>> |
definitions(InstanceDefinitions<W1> def1,
InstanceDefinitions<W2> def2,
TransformerFactory<W1,W2> factory) |
InstanceDefinitions<Higher<Higher<Witness.nested,W1>,W2>> |
definitions(InstanceDefinitions<W1> def1,
InstanceDefinitions<W2> def2,
TransformerFactory<W1,W2> factory,
Maybe<Higher<W2,?>> zero) |
<R> Nested<W1,W2,R> |
flatMap(java.util.function.Function<? super T,? extends Higher<W2,R>> fn) |
<R,X> Nested<W1,W2,R> |
flatMap(java.util.function.Function<? super X,? extends Higher<W2,R>> widenFn,
java.util.function.Function<? super T,? extends X> fn) |
<R> Nested<W1,W2,R> |
flatMapA(java.util.function.Function<? super T,? extends Active<W2,R>> fn) |
<C2,T> Higher<C2,Nested<W1,W2,T>> |
flatSequence(Applicative<C2> applicative,
Nested<W1,W2,Higher<C2,Nested<W1,W2,T>>> fgfa,
TransformerFactory<W1,W2> factory) |
static <W,T> Active<W,T> |
flatten(Nested<W,W,T> nested) |
<C2,R> Higher<C2,Nested<W1,W2,R>> |
flatTraverse(Applicative<C2> applicative,
java.util.function.Function<? super T,? extends Higher<C2,Nested<W1,W2,R>>> f,
TransformerFactory<W1,W2> factory) |
<R> R |
fold(java.util.function.Function<? super Higher<W1,Higher<W2,T>>,? extends R> fn) |
T |
foldBothl(T identity,
java.util.function.BinaryOperator<T> semigroup) |
T |
foldBothLeft(Monoid<T> monoid) |
T |
foldBothr(T identity,
java.util.function.BinaryOperator<T> semigroup) |
T |
foldBothRight(Monoid<T> monoid) |
Active<W1,T> |
foldl(Monoid<T> monoid) |
Active<W1,T> |
foldl(T identity,
java.util.function.BinaryOperator<T> semigroup) |
Higher<W1,T> |
foldLeft(Monoid<T> monoid) |
<R> R |
foldLeft(Monoid<T> monoid,
java.util.function.Function<? super Higher<W1,T>,? extends R> narrowK) |
Higher<W1,T> |
foldLeft(T identity,
java.util.function.BinaryOperator<T> semigroup) |
<R> Higher<W1,R> |
foldMap(Monoid<R> mb,
java.util.function.Function<? super T,? extends R> fn) |
<R> Active<W1,R> |
foldMapA(Monoid<R> mb,
java.util.function.Function<? super T,? extends R> fn) |
<R> R |
foldMapBoth(Monoid<R> mb,
java.util.function.Function<? super T,? extends R> fn) |
Active<W1,T> |
foldr(Monoid<T> monoid) |
Active<W1,T> |
foldr(T identity,
java.util.function.BinaryOperator<T> semigroup) |
Higher<W1,T> |
foldRight(Monoid<T> monoid) |
<R> R |
foldRight(Monoid<T> monoid,
java.util.function.Function<? super Higher<W1,T>,? extends R> narrowK) |
Higher<W1,T> |
foldRight(T identity,
java.util.function.BinaryOperator<T> semigroup) |
static <T> Nested<Witness.future,Witness.list,T> |
futureList(Future<? extends java.util.List<T>> futureList) |
static <T,X extends java.lang.Throwable> |
futureTry(Future<? extends Try<T,X>> futureTry) |
static <T> Nested<Witness.future,Witness.vectorX,T> |
futureVector(Future<VectorX<T>> futureList) |
static <L,R> Nested<Witness.future,Higher<Witness.xor,L>,R> |
futureXor(Future<? extends Xor<L,R>> futureXor) |
Higher<W1,Higher<W2,T>> |
getNested() |
<R> java.util.function.Function<Nested<W1,W2,T>,Nested<W1,W2,R>> |
lift(java.util.function.Function<? super T,? extends R> fn) |
static <T,X extends java.lang.Throwable> |
listTry(java.util.List<? extends Try<T,X>> futureTry) |
static <L,R> Nested<Witness.list,Higher<Witness.xor,L>,R> |
listXor(java.util.List<? extends Xor<L,R>> listXor) |
<R> Nested<W1,W2,R> |
map(java.util.function.Function<? super T,? extends R> fn)
Transform this functor using the supplied transformation function
|
<R> Nested<W1,W2,R> |
mapWithIndex(java.util.function.BiFunction<? super T,java.lang.Long,? extends R> f) |
static <W1,W2,T> Higher<W1,Higher<W2,T>> |
narrow(Higher<W1,? extends Higher<W2,? extends T>> nested) |
static <W1,W2,T> Nested<W1,W2,T> |
narrowK(Higher<Higher<Higher<Witness.nested,W1>,W2>,T> ds) |
static <W1,W2,T> Nested<W1,W2,T> |
of(Active<W1,? extends Higher<W2,? extends T>> nested,
InstanceDefinitions<W2> def2) |
static <W1,W2,T> Nested<W1,W2,T> |
of(Higher<W1,? extends Higher<W2,? extends T>> nested,
InstanceDefinitions<W1> def1,
InstanceDefinitions<W2> def2) |
static <T> Nested<Witness.optional,Witness.list,T> |
optionalList(java.util.Optional<? extends java.util.List<T>> optionalList) |
static <T> Nested<Witness.optional,Witness.stream,T> |
optionalStream(java.util.Optional<? extends java.util.stream.Stream<T>> optionalList) |
Nested<W1,W2,T> |
peek(java.util.function.Consumer<? super T> fn)
Peek at the current value of this Transformable, without transforming it
|
Maybe<Nested.Plus> |
plus() |
Nested.Plus |
plus(MonadPlus<W1> plus1,
MonadPlus<W2> plus2) |
Nested<W1,W2,T> |
plusNested(SemigroupK<W2,T> semigroupK,
Higher<W2,T> add) |
Nested.Plus |
plusUnsafe() |
<R> Active<W1,R> |
pure1(R value) |
<R> Nested<W1,W2,R> |
pure2(R value) |
<R> Nested<W1,W2,R> |
retry(java.util.function.Function<? super T,? extends R> fn)
Retry a transformation if it fails.
|
<R> Nested<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.
|
Nested<W1,W2,T> |
reverse() |
Nested<W2,W1,T> |
sequence() |
<C2,T> Higher<C2,Nested<W1,W2,T>> |
sequenceA(Applicative<C2> applicative,
Nested<W1,W2,Higher<C2,T>> ds) |
Active<W1,java.lang.Long> |
size() |
Active<W1,ReactiveSeq<T>> |
stream() |
ReactiveSeq<T> |
streamBoth() |
<R> Nested<W1,W2,R> |
tailRec(T initial,
java.util.function.Function<? super T,? extends Nested<W1,W2,? extends Xor<T,R>>> fn) |
<R> Nested<W1,W2,R> |
tailRecN(T initial,
java.util.function.Function<? super T,? extends Higher<W2,? extends Xor<T,R>>> fn) |
Active<W1,ListX<T>> |
toListX() |
ListX<T> |
toListXBoth() |
java.lang.String |
toString() |
long |
totalSize() |
<R> Nested<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
|
Transformer<W1,W2,T> |
transformer(TransformerFactory<W1,W2> factory) |
<R> Nested<W2,W1,R> |
traverse(java.util.function.Function<? super T,? extends R> fn) |
<C2,R> Higher<C2,Nested<W1,W2,R>> |
traverseA(Applicative<C2> applicative,
java.util.function.Function<? super T,? extends Higher<C2,R>> fn) |
Maybe<Nested.Unfolds> |
unfolds() |
Nested.Unfolds |
unfolds(Unfoldable<W2> unf) |
Nested.Unfolds |
unfoldsUnsafe() |
<T2,R> Nested<W1,W2,org.jooq.lambda.tuple.Tuple2<T,T2>> |
zip(Higher<W2,T2> fb) |
<T2,R> Nested<W1,W2,R> |
zip(Higher<W2,T2> fb,
java.util.function.BiFunction<? super T,? super T2,? extends R> f) |
<R> Nested<W1,W2,org.jooq.lambda.tuple.Tuple2<T,java.lang.Long>> |
zipWithIndex() |
public final InstanceDefinitions<W1> def1
public final InstanceDefinitions<W2> def2
public Transformer<W1,W2,T> transformer(TransformerFactory<W1,W2> factory)
public static <W1,W2,T> Nested<W1,W2,T> of(Higher<W1,? extends Higher<W2,? extends T>> nested, InstanceDefinitions<W1> def1, InstanceDefinitions<W2> def2)
public static <W1,W2,T> Nested<W1,W2,T> of(Active<W1,? extends Higher<W2,? extends T>> nested, InstanceDefinitions<W2> def2)
public static <W1,W2,T> Higher<W1,Higher<W2,T>> narrow(Higher<W1,? extends Higher<W2,? extends T>> nested)
public <R> Nested<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 Active<W1,ReactiveSeq<T>> stream()
public ReactiveSeq<T> streamBoth()
public long totalSize()
public <R> Nested<W1,W2,R> mapWithIndex(java.util.function.BiFunction<? super T,java.lang.Long,? extends R> f)
public Nested<W1,W2,T> peek(java.util.function.Consumer<? super T> fn)
Transformable
of(1,2,3).map(System.out::println)
1
2
3
peek
in interface Transformable<T>
fn
- Consumer that recieves each element from this Transformablepublic <R> java.util.function.Function<Nested<W1,W2,T>,Nested<W1,W2,R>> lift(java.util.function.Function<? super T,? extends R> fn)
public <R> Nested<W1,W2,R> flatMap(java.util.function.Function<? super T,? extends Higher<W2,R>> fn)
public <R,X> Nested<W1,W2,R> flatMap(java.util.function.Function<? super X,? extends Higher<W2,R>> widenFn, java.util.function.Function<? super T,? extends X> fn)
public <T2,R> Nested<W1,W2,R> zip(Higher<W2,T2> fb, java.util.function.BiFunction<? super T,? super T2,? extends R> f)
public <C> cyclops.typeclasses.Nested.Narrowed<C> concreteMonoid(Kleisli<W2,C,T> widen, Cokleisli<W2,T,C> narrow)
public <C,R> cyclops.typeclasses.Nested.NarrowedFlatMap<C,R> concreteFlatMap(Kleisli<W2,C,R> widen)
public <C,R> cyclops.typeclasses.Nested.NarrowedApplicative<C,R> concreteAp(Kleisli<W2,C,java.util.function.Function<T,R>> widen)
public <C,R> cyclops.typeclasses.Nested.NarrowedTailRec<C,R> concreteTailRec(Kleisli<W2,C,Xor<T,R>> widen)
public <S,R> Nested.Converter<W1,S> concreteConversion(java.util.function.Function<? super Higher<W2,T>,? extends S> narrow2)
public <R> Nested<W1,W2,R> flatMapA(java.util.function.Function<? super T,? extends Active<W2,R>> fn)
public <R> Nested<W1,W2,R> tailRecN(T initial, java.util.function.Function<? super T,? extends Higher<W2,? extends Xor<T,R>>> fn)
public <R> Nested<W1,W2,R> tailRec(T initial, java.util.function.Function<? super T,? extends Nested<W1,W2,? extends Xor<T,R>>> fn)
public Nested.Unfolds unfolds(Unfoldable<W2> unf)
public Nested.Plus plus(MonadPlus<W1> plus1, MonadPlus<W2> plus2)
public Nested.Unfolds unfoldsUnsafe()
public Nested.Plus plusUnsafe()
public Maybe<Nested.Unfolds> unfolds()
public Maybe<Nested.Plus> plus()
public <R> R foldMapBoth(Monoid<R> mb, java.util.function.Function<? super T,? extends R> fn)
public <R> R foldRight(Monoid<T> monoid, java.util.function.Function<? super Higher<W1,T>,? extends R> narrowK)
public <R> R foldLeft(Monoid<T> monoid, java.util.function.Function<? super Higher<W1,T>,? extends R> narrowK)
public <R> Active<W1,R> foldMapA(Monoid<R> mb, java.util.function.Function<? super T,? extends R> fn)
public <R> Higher<W1,R> foldMap(Monoid<R> mb, java.util.function.Function<? super T,? extends R> fn)
public <C2,R> Higher<C2,Nested<W1,W2,R>> traverseA(Applicative<C2> applicative, java.util.function.Function<? super T,? extends Higher<C2,R>> fn)
public <C2,T> Higher<C2,Nested<W1,W2,T>> sequenceA(Applicative<C2> applicative, Nested<W1,W2,Higher<C2,T>> ds)
public <C2,R> Higher<C2,Nested<W1,W2,R>> flatTraverse(Applicative<C2> applicative, java.util.function.Function<? super T,? extends Higher<C2,Nested<W1,W2,R>>> f, TransformerFactory<W1,W2> factory)
public <C2,T> Higher<C2,Nested<W1,W2,T>> flatSequence(Applicative<C2> applicative, Nested<W1,W2,Higher<C2,Nested<W1,W2,T>>> fgfa, TransformerFactory<W1,W2> factory)
public java.lang.String toString()
toString
in class java.lang.Object
public <U> Nested<W1,W2,U> cast(java.lang.Class<? extends U> type)
Transformable
ClassCastException
.
// ClassCastException ReactiveSeq.of(1, "a", 2, "b", 3).cast(Integer.class)cast
in interface Transformable<T>
public <R> Nested<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> Nested<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> Nested<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 static <T> Nested<Witness.completableFuture,Witness.stream,T> completableFutureStream(java.util.concurrent.CompletableFuture<? extends java.util.stream.Stream<T>> optionalList)
public static <T> Nested<Witness.optional,Witness.stream,T> optionalStream(java.util.Optional<? extends java.util.stream.Stream<T>> optionalList)
public static <T> Nested<Witness.optional,Witness.list,T> optionalList(java.util.Optional<? extends java.util.List<T>> optionalList)
public static <T,X extends java.lang.Throwable> Nested<Witness.future,Higher<Witness.tryType,X>,T> futureTry(Future<? extends Try<T,X>> futureTry)
public static <T,X extends java.lang.Throwable> Nested<Witness.list,Higher<Witness.tryType,X>,T> listTry(java.util.List<? extends Try<T,X>> futureTry)
public static <L,R> Nested<Witness.list,Higher<Witness.xor,L>,R> listXor(java.util.List<? extends Xor<L,R>> listXor)
public static <L,R> Nested<Witness.future,Higher<Witness.xor,L>,R> futureXor(Future<? extends Xor<L,R>> futureXor)
public static <T> Nested<Witness.future,Witness.list,T> futureList(Future<? extends java.util.List<T>> futureList)
public static <T> Nested<Witness.future,Witness.vectorX,T> futureVector(Future<VectorX<T>> futureList)
public static <W1,W2,T> Nested<W1,W2,T> narrowK(Higher<Higher<Higher<Witness.nested,W1>,W2>,T> ds)
public Maybe<Nested.NestedComprehensions.Guarded<W1,W2,T>> comprehensionsGuarded(TransformerFactory<W1,W2> factory)
public Nested.NestedComprehensions<W1,W2,T> comprehensions(TransformerFactory<W1,W2> factory)
public Maybe<Comprehensions.Guarded<Higher<Higher<Witness.nested,W1>,W2>>> comprehensionsGuardedHk(TransformerFactory<W1,W2> factory)
public Comprehensions<Higher<Higher<Witness.nested,W1>,W2>> comprehensionsHk(TransformerFactory<W1,W2> factory)
public Active<Higher<Higher<Witness.nested,W1>,W2>,T> allTypeclasses(TransformerFactory<W1,W2> factory)
public InstanceDefinitions<Higher<Higher<Witness.nested,W1>,W2>> definitions(InstanceDefinitions<W1> def1, InstanceDefinitions<W2> def2, TransformerFactory<W1,W2> factory)
public InstanceDefinitions<Higher<Higher<Witness.nested,W1>,W2>> definitions(InstanceDefinitions<W1> def1, InstanceDefinitions<W2> def2, TransformerFactory<W1,W2> factory, Maybe<Higher<W2,?>> zero)