scanl package:vector

O(n) Left-to-right scan.
scanl f z <x1,...,xn> = <y1,...,y(n+1)>
where y1 = z
yi = f y(i-1) x(i-1)

Examples

>>> import qualified Data.Vector as V

>>> V.scanl (+) 0 (V.fromList [1,2,3,4])
[0,1,3,6,10]
Haskell-style scan
Haskell-style scan
O(n) Left-to-right scan.
scanl f z <x1,...,xn> = <y1,...,y(n+1)>
where y1 = z
yi = f y(i-1) x(i-1)

Examples

>>> import qualified Data.Vector.Strict as V

>>> V.scanl (+) 0 (V.fromList [1,2,3,4])
[0,1,3,6,10]
O(n) Left-to-right scan.
scanl f z <x1,...,xn> = <y1,...,y(n+1)>
where y1 = z
yi = f y(i-1) x(i-1)

Examples

>>> import qualified Data.Vector.Primitive as VP

>>> VP.scanl (+) 0 (VP.fromList [1,2,3,4 :: Int])
[0,1,3,6,10]
O(n) Left-to-right scan.
scanl f z <x1,...,xn> = <y1,...,y(n+1)>
where y1 = z
yi = f y(i-1) x(i-1)

Examples

>>> import qualified Data.Vector.Storable as VS

>>> VS.scanl (+) 0 (VS.fromList [1,2,3,4 :: Int])
[0,1,3,6,10]
O(n) Left-to-right scan.
scanl f z <x1,...,xn> = <y1,...,y(n+1)>
where y1 = z
yi = f y(i-1) x(i-1)

Examples

>>> import qualified Data.Vector.Unboxed as VU

>>> VU.scanl (+) 0 (VU.fromList [1,2,3,4 :: Int])
[0,1,3,6,10]
O(n) Left-to-right scan with strict accumulator.
O(n) Initial-value free left-to-right scan over a vector.
scanl f <x1,...,xn> = <y1,...,yn>
where y1 = x1
yi = f y(i-1) xi
Note: Since 0.13, application of this to an empty vector no longer results in an error; instead it produces an empty vector.

Examples

>>> import qualified Data.Vector as V

>>> V.scanl1 min $ V.fromListN 5 [4,2,4,1,3]
[4,2,2,1,1]

>>> V.scanl1 max $ V.fromListN 5 [1,3,2,5,4]
[1,3,3,5,5]

>>> V.scanl1 min (V.empty :: V.Vector Int)
[]
O(n) Initial-value free left-to-right scan over a vector with a strict accumulator. Note: Since 0.13, application of this to an empty vector no longer results in an error; instead it produces an empty vector.

Examples

>>> import qualified Data.Vector as V

>>> V.scanl1' min $ V.fromListN 5 [4,2,4,1,3]
[4,2,2,1,1]

>>> V.scanl1' max $ V.fromListN 5 [1,3,2,5,4]
[1,3,3,5,5]

>>> V.scanl1' min (V.empty :: V.Vector Int)
[]
Haskell-style scan with strict accumulator
Initial-value free scan over a Bundle
Initial-value free scan over a Bundle with a strict accumulator
Haskell-style scan with strict accumulator
Initial-value free scan over a Bundle
Initial-value free scan over a Bundle with a strict accumulator
Initial-value free scan over a Bundle with a monadic operator
Initial-value free scan over a Bundle with a strict accumulator and a monadic operator
Haskell-style scan with a monadic operator
Haskell-style scan with strict accumulator and a monadic operator