Class FoldLeft<A,B>
- java.lang.Object
-
- com.jnape.palatable.lambda.functions.builtin.fn3.FoldLeft<A,B>
-
- Type Parameters:
A
- The Iterable element typeB
- The accumulation type
- All Implemented Interfaces:
Fn1<Fn2<? super B,? super A,? extends B>,Fn1<B,Fn1<java.lang.Iterable<A>,B>>>
,Fn2<Fn2<? super B,? super A,? extends B>,B,Fn1<java.lang.Iterable<A>,B>>
,Fn3<Fn2<? super B,? super A,? extends B>,B,java.lang.Iterable<A>,B>
,Applicative<Fn1<B,Fn1<java.lang.Iterable<A>,B>>,Fn1<Fn2<? super B,? super A,? extends B>,?>>
,Cartesian<Fn2<? super B,? super A,? extends B>,Fn1<B,Fn1<java.lang.Iterable<A>,B>>,Fn1<?,?>>
,Cocartesian<Fn2<? super B,? super A,? extends B>,Fn1<B,Fn1<java.lang.Iterable<A>,B>>,Fn1<?,?>>
,Contravariant<Fn2<? super B,? super A,? extends B>,Profunctor<?,Fn1<B,Fn1<java.lang.Iterable<A>,B>>,Fn1<?,?>>>
,Functor<Fn1<B,Fn1<java.lang.Iterable<A>,B>>,Fn1<Fn2<? super B,? super A,? extends B>,?>>
,Profunctor<Fn2<? super B,? super A,? extends B>,Fn1<B,Fn1<java.lang.Iterable<A>,B>>,Fn1<?,?>>
,Monad<Fn1<B,Fn1<java.lang.Iterable<A>,B>>,Fn1<Fn2<? super B,? super A,? extends B>,?>>
,MonadReader<Fn2<? super B,? super A,? extends B>,Fn1<B,Fn1<java.lang.Iterable<A>,B>>,Fn1<Fn2<? super B,? super A,? extends B>,?>>
,MonadRec<Fn1<B,Fn1<java.lang.Iterable<A>,B>>,Fn1<Fn2<? super B,? super A,? extends B>,?>>
,MonadWriter<Fn2<? super B,? super A,? extends B>,Fn1<B,Fn1<java.lang.Iterable<A>,B>>,Fn1<Fn2<? super B,? super A,? extends B>,?>>
public final class FoldLeft<A,B> extends java.lang.Object implements Fn3<Fn2<? super B,? super A,? extends B>,B,java.lang.Iterable<A>,B>
Given anIterable
ofA
s, a starting valueB
, and a
, iteratively accumulate over theFn2
<B, A, B>Iterable
, ultimately returning a finalB
value. If theIterable
is empty, just return the startingB
value. Note that, as the name implies, this function accumulates from left to right, such thatfoldLeft(f, 0, asList(1, 2, 3, 4, 5))
is evaluated asf(f(f(f(f(0, 1), 2), 3), 4), 5)
.For more information, read about Catamorphisms.
- See Also:
FoldRight
-
-
Constructor Summary
Constructors Modifier Constructor Description private
FoldLeft()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description B
checkedApply(Fn2<? super B,? super A,? extends B> fn, B acc, java.lang.Iterable<A> as)
static <A,B>
FoldLeft<A,B>foldLeft()
static <A,B>
Fn2<B,java.lang.Iterable<A>,B>foldLeft(Fn2<? super B,? super A,? extends B> fn)
static <A,B>
Fn1<java.lang.Iterable<A>,B>foldLeft(Fn2<? super B,? super A,? extends B> fn, B acc)
static <A,B>
BfoldLeft(Fn2<? super B,? super A,? extends B> fn, 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 FoldLeft<?,?> INSTANCE
-
-
Method Detail
-
checkedApply
public B checkedApply(Fn2<? super B,? super A,? extends B> fn, B acc, java.lang.Iterable<A> as)
-
foldLeft
public static <A,B> FoldLeft<A,B> foldLeft()
-
foldLeft
public static <A,B> Fn2<B,java.lang.Iterable<A>,B> foldLeft(Fn2<? super B,? super A,? extends B> fn)
-
foldLeft
public static <A,B> Fn1<java.lang.Iterable<A>,B> foldLeft(Fn2<? super B,? super A,? extends B> fn, B acc)
-
foldLeft
public static <A,B> B foldLeft(Fn2<? super B,? super A,? extends B> fn, B acc, java.lang.Iterable<A> as)
-
-