foldl1 package:base

A variant of foldl that has no base case, and thus may only be applied to non-empty structures. This function is non-total and will raise a runtime exception if the structure happens to be empty.
foldl1 f = foldl1 f . toList

Examples

Basic usage:
>>> foldl1 (+) [1..4]
10
>>> foldl1 (+) []
*** Exception: Prelude.foldl1: empty list
>>> foldl1 (+) Nothing
*** Exception: foldl1: empty structure
>>> foldl1 (-) [1..4]
-8
>>> foldl1 (&&) [True, False, True, True]
False
>>> foldl1 (||) [False, False, True, True]
True
>>> foldl1 (+) [1..]
* Hangs forever *
A variant of foldlMap1 where the leftmost element maps to itself.
foldl1 is a variant of foldl that has no starting value argument, and thus must be applied to non-empty lists. Note that unlike foldl, the accumulated value must be of the same type as the list elements.
>>> foldl1 (+) [1..4]
10

>>> foldl1 (+) []
*** Exception: Prelude.foldl1: empty list

>>> foldl1 (-) [1..4]
-8

>>> foldl1 (&&) [True, False, True, True]
False

>>> foldl1 (||) [False, False, True, True]
True

>>> foldl1 (+) [1..]
* Hangs forever *
A strict version of foldl1.
A variant of foldlMap1' where the leftmost element maps to itself.
A left fold over the elements with no starting value
A variant of bifoldl that has no base case, and thus may only be applied to non-empty structures.

Examples

Basic usage:
>>> bifoldl1 (+) (5, 7)
12
>>> bifoldl1 (+) (Right 7)
7
>>> bifoldl1 (+) (Left 5)
5
> bifoldl1 (+) (BiList [1, 2] [3, 4])
10 -- ((1 + 2) + 3) + 4
>>> bifoldl1 (+) (BiList [1, 2] [])
3
On empty structures, this function throws an exception:
>>> bifoldl1 (+) (BiList [] [])
*** Exception: bifoldl1: empty structure
...