foldr1

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
foldr1 is a variant of foldr that has no starting value argument, and thus must be applied to non-empty ByteStrings An exception will be thrown in the case of an empty ByteString.
foldr1 is a variant of foldr that has no starting value argument, and thus must be applied to non-empty ByteStrings
foldr1 is a variant of foldr that has no starting value argument, and thus must be applied to non-empty ByteStrings
foldr1 is a variant of foldr that has no starting value argument, and thus must be applied to non-empty ShortByteStrings An exception will be thrown in the case of an empty ShortByteString.
O(n) A variant of foldr that has no starting value argument, and thus must be applied to a non-empty Text.
foldr1 is a variant of foldr that has no starting value argument, and thus must be applied to non-empty streams. Properties
foldr1 f . stream = foldr1 f
Combines the elements of a non-empty structure using a binary function f.
>>> foldr1 (+) 0 (1 :| [2, 3])
6

>>> foldr1 (+) 1 $ Identity 3
4
foldr1 is a variant of foldr that has no starting value argument, and thus must be applied to non-empty ByteStrings
foldr1 is a variant of foldr that has no starting value argument, and thus must be applied to non-empty ByteStrings An exception will be thrown in the case of an empty ByteString.
A variant of foldr that has no base case, and thus may only be applied to non-empty structures.
foldr1 f = foldr1 f . toList
O(n) A variant of foldr that has no starting value argument, and thus must be applied to a non-empty Text. Subject to fusion.
O(n) Right fold on non-empty vectors
O(n) Right fold on non-empty vectors
O(n) Right fold on non-empty vectors
O(n) Right fold on non-empty vectors
Reduces the characters of the ShortText with the binary operator.
>>> foldr1 max "abcdcba"
'd'
>>> foldr1 const "abcd"
'a'
>>> foldr1 (flip const) "abcd"
'd'
Note: Will throw an error exception if index is out of bounds.
Like foldr, but with no starting value
O(n) A variant of foldr that has no starting value argument, and thus must be applied to a non-empty JSString. Subject to fusion.
Lazy right fold for non-empty streams, using first element as the starting value. Returns Nothing if the stream is empty.
foldr1 is a variant of foldr that has no starting value argument, and thus must be applied to non-empty Vectors It is a checked error to pass an empty Vector.