on master help sign in
Adds scanl1 to Data.Vect

This adds scanl1, matching the scanl and scanl1 scans in Data.List. The documentation for scanl1, and added documentation for scanl, in Data.Vect is borrowed from Data.List.

commitecce09c075b8dde6bff3d3f2b2f19eacf92add1b authorRob Stewart <robstewart57@gmail.com> dateThu 16 Nov 2017, 18:14 (9 years ago) parent21ab196
1 file changed+10
libs/base/Data/Vect.idr+10
libs/base/Data/Vect.idr+10
@@ -326,10 +326,20 @@ foldl1 f (x::xs) = foldl f x xs
326326-- Scans
327327--------------------------------------------------------------------------------
328328
329+||| The scanl function is similar to foldl, but returns all the intermediate
330+||| accumulator states in the form of a vector.
329331scanl : (res -> elem -> res) -> res -> Vect len elem -> Vect (S len) res
330332scanl f q [] = [q]
331333scanl f q (x::xs) = q :: scanl f (f q x) xs
332334
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+
333343--------------------------------------------------------------------------------
334344-- Membership tests
335345--------------------------------------------------------------------------------