head (scanr f z xs) == foldr f z xs.
>>> scanr (+) 0 [1..4] [10,9,7,4,0]
>>> scanr (+) 42 [] [42]
>>> scanr (-) 100 [1..4] [98,-97,99,-96,100]
>>> scanr (\nextChar reversedString -> nextChar : reversedString) "foo" ['a', 'b', 'c', 'd'] ["abcdfoo","bcdfoo","cdfoo","dfoo","foo"]
>>> force $ scanr (+) 0 [1..] *** Exception: stack overflow
head (scanr f z xs) == foldr f z xs.
>>> scanr (+) 0 [1..4] [10,9,7,4,0] >>> scanr (+) 42 [] [42] >>> scanr (-) 100 [1..4] [98,-97,99,-96,100] >>> scanr (\nextChar reversedString -> nextChar : reversedString) "foo" ['a', 'b', 'c', 'd'] ["abcdfoo","bcdfoo","cdfoo","dfoo","foo"] >>> force $ scanr (+) 0 [1..] *** Exception: stack overflow
>>> import Data.Maybe (fromJust)
>>> let avg = Scanr.teeWith (/) Scanr.sum (fmap fromIntegral Scanr.length)
>>> s = Stream.enumerateFromTo 1.0 100.0
>>> :{
Stream.fold Fold.toList
$ fmap fst
$ Stream.takeWhile (\(_,x) -> x <= 10)
$ Stream.scanr (Scanr.tee Scanr.identity avg) s
:}
[1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0,10.0,11.0,12.0,13.0,14.0,15.0,16.0,17.0,18.0,19.0]