Class FoldRight<A,B>

java.lang.Object
com.jnape.palatable.lambda.functions.builtin.fn3.FoldRight<A,B>
Type Parameters:
A - The Iterable element type
B - The accumulation type
All Implemented Interfaces:
Fn1<Fn2<? super A,? super Lazy<B>,? extends Lazy<B>>,Fn1<Lazy<B>,Fn1<Iterable<A>,Lazy<B>>>>, Fn2<Fn2<? super A,? super Lazy<B>,? extends Lazy<B>>,Lazy<B>,Fn1<Iterable<A>,Lazy<B>>>, Fn3<Fn2<? super A,? super Lazy<B>,? extends Lazy<B>>,Lazy<B>,Iterable<A>,Lazy<B>>, Applicative<Fn1<Lazy<B>,Fn1<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<Iterable<A>,Lazy<B>>>,Fn1<?,?>>, Cocartesian<Fn2<? super A,? super Lazy<B>,? extends Lazy<B>>,Fn1<Lazy<B>,Fn1<Iterable<A>,Lazy<B>>>,Fn1<?,?>>, Contravariant<Fn2<? super A,? super Lazy<B>,? extends Lazy<B>>,Profunctor<?,Fn1<Lazy<B>,Fn1<Iterable<A>,Lazy<B>>>,Fn1<?,?>>>, Functor<Fn1<Lazy<B>,Fn1<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<Iterable<A>,Lazy<B>>>,Fn1<?,?>>, Monad<Fn1<Lazy<B>,Fn1<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<Iterable<A>,Lazy<B>>>,Fn1<Fn2<? super A,? super Lazy<B>,? extends Lazy<B>>,?>>, MonadRec<Fn1<Lazy<B>,Fn1<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<Iterable<A>,Lazy<B>>>,Fn1<Fn2<? super A,? super Lazy<B>,? extends Lazy<B>>,?>>

public final class FoldRight<A,B> extends Object implements Fn3<Fn2<? super A,? super Lazy<B>,? extends Lazy<B>>,Lazy<B>,Iterable<A>,Lazy<B>>
Given an Iterable of As, a starting lazy value B, and a Fn2<A, Lazy<B>, Lazy<B>>, iteratively accumulate over the Iterable, ultimately returning a final Lazy<B> value. If the Iterable is empty, just return the starting Lazy<B> value. This function is computationally the iterative inverse of FoldLeft, but uses Lazy to allow support stack-safe execution.

Example:

 
 Lazy<Iterable<Integer>> lazyCopy = foldRight(
     (head, lazyTail) -&gt; lazy(cons(head, () -&gt; lazyTail.value().iterator())),
     lazy(emptyList()),
     iterate(x -&gt; x + 1, 0));
 Iterable<Integer> copy = () -&gt; 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: