O(n) scanl is similar to
foldl, but returns a
list of successive reduced values from the left. Performs replacement
on invalid scalar values.
scanl f z [x1, x2, ...] == [z, z `f` x1, (z `f` x1) `f` x2, ...]
Note that
last (scanl f z xs) == foldl f z xs.