Class FoldRight<A,B>
- java.lang.Object
-
- com.jnape.palatable.lambda.functions.builtin.fn3.FoldRight<A,B>
-
- Type Parameters:
A
- The Iterable element typeB
- The accumulation type
- All Implemented Interfaces:
Fn1<Fn2<? super A,? super Lazy<B>,? extends Lazy<B>>,Fn1<Lazy<B>,Fn1<java.lang.Iterable<A>,Lazy<B>>>>
,Fn2<Fn2<? super A,? super Lazy<B>,? extends Lazy<B>>,Lazy<B>,Fn1<java.lang.Iterable<A>,Lazy<B>>>
,Fn3<Fn2<? super A,? super Lazy<B>,? extends Lazy<B>>,Lazy<B>,java.lang.Iterable<A>,Lazy<B>>
,Applicative<Fn1<Lazy<B>,Fn1<java.lang.Iterable<A>,Lazy<B>>>,Fn1<Fn2<? super A,? super Lazy<B>,? extends Lazy<B>>,?>>
,Cartesian<Fn2<? super A,? super Lazy<B>,? extends Lazy<B>>,Fn1<Lazy<B>,Fn1<java.lang.Iterable<A>,Lazy<B>>>,Fn1<?,?>>
,Cocartesian<Fn2<? super A,? super Lazy<B>,? extends Lazy<B>>,Fn1<Lazy<B>,Fn1<java.lang.Iterable<A>,Lazy<B>>>,Fn1<?,?>>
,Contravariant<Fn2<? super A,? super Lazy<B>,? extends Lazy<B>>,Profunctor<?,Fn1<Lazy<B>,Fn1<java.lang.Iterable<A>,Lazy<B>>>,Fn1<?,?>>>
,Functor<Fn1<Lazy<B>,Fn1<java.lang.Iterable<A>,Lazy<B>>>,Fn1<Fn2<? super A,? super Lazy<B>,? extends Lazy<B>>,?>>
,Profunctor<Fn2<? super A,? super Lazy<B>,? extends Lazy<B>>,Fn1<Lazy<B>,Fn1<java.lang.Iterable<A>,Lazy<B>>>,Fn1<?,?>>
,Monad<Fn1<Lazy<B>,Fn1<java.lang.Iterable<A>,Lazy<B>>>,Fn1<Fn2<? super A,? super Lazy<B>,? extends Lazy<B>>,?>>
,MonadReader<Fn2<? super A,? super Lazy<B>,? extends Lazy<B>>,Fn1<Lazy<B>,Fn1<java.lang.Iterable<A>,Lazy<B>>>,Fn1<Fn2<? super A,? super Lazy<B>,? extends Lazy<B>>,?>>
,MonadRec<Fn1<Lazy<B>,Fn1<java.lang.Iterable<A>,Lazy<B>>>,Fn1<Fn2<? super A,? super Lazy<B>,? extends Lazy<B>>,?>>
,MonadWriter<Fn2<? super A,? super Lazy<B>,? extends Lazy<B>>,Fn1<Lazy<B>,Fn1<java.lang.Iterable<A>,Lazy<B>>>,Fn1<Fn2<? super A,? super Lazy<B>,? extends Lazy<B>>,?>>
public final class FoldRight<A,B> extends java.lang.Object implements Fn3<Fn2<? super A,? super Lazy<B>,? extends Lazy<B>>,Lazy<B>,java.lang.Iterable<A>,Lazy<B>>
Given anIterable
ofA
s, a startinglazy
valueB
, and a
, iteratively accumulate over theFn2
<A,Lazy
<B>,Lazy
<B>>Iterable
, ultimately returning a final
value. If theLazy
<B>Iterable
is empty, just return the starting
value. This function is computationally the iterative inverse ofLazy
<B>FoldLeft
, but usesLazy
to allow support stack-safe execution.Example:
Lazy<Iterable<Integer>> lazyCopy = foldRight( (head, lazyTail) -> lazy(cons(head, () -> lazyTail.value().iterator())), lazy(emptyList()), iterate(x -> x + 1, 0)); Iterable<Integer> copy = () -> lazyCopy.value().iterator(); take(3, copy).forEach(System.out::println); // prints "1, 2, 3" take(3, copy).forEach(System.out::println); // prints "1, 2, 3"
For more information, read about Catamorphisms.
- See Also:
FoldLeft
-
-
Constructor Summary
Constructors Modifier Constructor Description private
FoldRight()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Lazy<B>
checkedApply(Fn2<? super A,? super Lazy<B>,? extends Lazy<B>> fn, Lazy<B> acc, java.lang.Iterable<A> as)
static <A,B>
FoldRight<A,B>foldRight()
static <A,B>
Fn2<Lazy<B>,java.lang.Iterable<A>,Lazy<B>>foldRight(Fn2<? super A,? super Lazy<B>,? extends Lazy<B>> fn)
static <A,B>
Fn1<java.lang.Iterable<A>,Lazy<B>>foldRight(Fn2<? super A,? super Lazy<B>,? extends Lazy<B>> fn, Lazy<B> acc)
static <A,B>
Lazy<B>foldRight(Fn2<? super A,? super Lazy<B>,? extends Lazy<B>> fn, Lazy<B> acc, java.lang.Iterable<A> as)
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.jnape.palatable.lambda.functions.Fn1
andThen, carry, cartesian, censor, choose, cocartesian, diMap, diMapR, discardL, flatMap, fmap, lazyZip, listens, local, pure, self, thunk, toFunction, trampolineM, zip, zip
-
Methods inherited from interface com.jnape.palatable.lambda.functions.Fn2
checkedApply, toBiFunction
-
-
-
-
Field Detail
-
INSTANCE
private static final FoldRight<?,?> INSTANCE
-
-
Method Detail
-
checkedApply
public Lazy<B> checkedApply(Fn2<? super A,? super Lazy<B>,? extends Lazy<B>> fn, Lazy<B> acc, java.lang.Iterable<A> as)
-
foldRight
public static <A,B> FoldRight<A,B> foldRight()
-
foldRight
public static <A,B> Fn2<Lazy<B>,java.lang.Iterable<A>,Lazy<B>> foldRight(Fn2<? super A,? super Lazy<B>,? extends Lazy<B>> fn)
-
foldRight
public static <A,B> Fn1<java.lang.Iterable<A>,Lazy<B>> foldRight(Fn2<? super A,? super Lazy<B>,? extends Lazy<B>> fn, Lazy<B> acc)
-
-