ZVON > References > Haskell reference
| Indexes | Syntax | >> Prelude << | Ratio | Complex | Numeric | Ix | Array | List | Maybe | Char | Monad | IO | Directory | System | Time | Locale | CPUTime | Random

Module: Prelude
Function: scanr
Type: (a -> b -> b) -> b -> [a] -> [b]
Description: it takes the second argument and the last item of the list and applies the function, then it takes the penultimate item from the end and the result, and so on. It returns the list of intermediate and final results.
Related: foldl, foldl1, foldr, foldr1, scanl, scanl1, scanr1

Example 1

Input: scanr (+) 5 [1,2,3,4]

Output: [15,14,12,9,5]

Example 2

Input: scanr (/) 2 [8,12,24,4]

Output: [8.0,1.0,12.0,2.0,2.0]

Example 3

Input: scanr (/) 3 []

Output: [3.0]

Example 4

Input: scanr (&&) True [1>2,3>2,5==5]

Output: [False,True,True,True]

Example 5

Input: scanr max 18 [3,6,12,4,55,11]

Output: [55,55,55,55,55,18,18]

Example 6

Input: scanr max 111 [3,6,12,4,55,11]

Output: [111,111,111,111,111,111,111]

Example 7

Input: scanr (\x y -> (x+y)/2) 54 [12,4,10,6]

Output: [12.0,12.0,20.0,30.0,54.0]