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 *