A
- The Iterable element typeB
- The accumulation typepublic final class FoldRight<A,B> extends Object implements Fn3<Fn2<? super A,? super Lazy<B>,? extends Lazy<B>>,Lazy<B>,Iterable<A>,Lazy<B>>
Iterable
of A
s, 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) -> 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.
FoldLeft
Modifier and Type | Method and Description |
---|---|
Lazy<B> |
checkedApply(Fn2<? super A,? super Lazy<B>,? extends Lazy<B>> fn,
Lazy<B> acc,
Iterable<A> as) |
static <A,B> FoldRight<A,B> |
foldRight() |
static <A,B> Fn2<Lazy<B>,Iterable<A>,Lazy<B>> |
foldRight(Fn2<? super A,? super Lazy<B>,? extends Lazy<B>> fn) |
static <A,B> Fn1<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,
Iterable<A> as) |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
apply, apply, apply, checkedApply, compose, contraMap, diMapL, discardR, flip, fn3, fn3, fn3, uncurry, widen
checkedApply, curried, curry, fn2, fromBiFunction, toBiFunction
public Lazy<B> checkedApply(Fn2<? super A,? super Lazy<B>,? extends Lazy<B>> fn, Lazy<B> acc, Iterable<A> as)
public static <A,B> FoldRight<A,B> foldRight()
public static <A,B> Fn2<Lazy<B>,Iterable<A>,Lazy<B>> foldRight(Fn2<? super A,? super Lazy<B>,? extends Lazy<B>> fn)
public static <A,B> Fn1<Iterable<A>,Lazy<B>> foldRight(Fn2<? super A,? super Lazy<B>,? extends Lazy<B>> fn, Lazy<B> acc)