foldr1 package:base

A variant of foldr 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.

Examples

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

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

>>> foldr1 (-) [1..4]
-2

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

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

>>> force $ foldr1 (+) [1..]
*** Exception: stack overflow
A variant of foldrMap1' where the rightmost element maps to itself.
A right fold over the elements with no starting value
A variant of bifoldr that has no base case, and thus may only be applied to non-empty structures.

Examples

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