on master help sign in
Adds scanl1 to Data.Vect
ecce09cRob Stewart
libs/base/Data/Vect.idr+10
@@ -326,10 +326,20 @@ foldl1 f (x::xs) = foldl f x xs
326-- Scans
326-- Scans
327--------------------------------------------------------------------------------
327--------------------------------------------------------------------------------
328
328
329+||| The scanl function is similar to foldl, but returns all the intermediate
330+||| accumulator states in the form of a vector.
329scanl : (res -> elem -> res) -> res -> Vect len elem -> Vect (S len) res
331scanl : (res -> elem -> res) -> res -> Vect len elem -> Vect (S len) res
330scanl f q [] = [q]
332scanl f q [] = [q]
331scanl f q (x::xs) = q :: scanl f (f q x) xs
333scanl f q (x::xs) = q :: scanl f (f q x) xs
332
334
335+||| The scanl1 function is a variant of scanl that doesn't require an explicit
336+||| starting value.
337+||| It assumes the first element of the vector to be the starting value and then
338+||| starts the fold with the element following it.
339+scanl1 : (elem -> elem -> elem) -> Vect len elem -> Vect len elem
340+scanl1 f [] = []
341+scanl1 f (x::xs) = scanl f x xs
342+
333--------------------------------------------------------------------------------
343--------------------------------------------------------------------------------
334-- Membership tests
344-- Membership tests
335--------------------------------------------------------------------------------
345--------------------------------------------------------------------------------