Methods
(static) foldl(f, z, xs) → {*}
Left-associative fold of a structure (i.e. fold from the end to the beginning, rather than from
the beginning to the end, as with foldr
, the right-associative version). This function
currently only works with List
objects but should be generalized to work with all Foldable
types, as in Haskell.
Haskell> foldl :: Foldable t => (b -> a -> b) -> b -> t a -> b
Parameters:
Name | Type | Description |
---|---|---|
f |
function | The function to map over the |
z |
* | An accumulator value |
xs |
List | The |
- Source:
Returns:
The result of applying the function to the List
and the accumulator
- Type
- *
Example
const lst = list(1,2,3);
const f = (x, y) => x - y;
foldl(f, 0, lst); // => -6