on master help sign in
Merge pull request #4199 from robstewart57/vect-scanl1

Adds scanl1 to Data.Vect

commit8f8c93f454fd8b4cae451df9b690374e69d841de authorAhmad Salim Al-Sibahi <asal@itu.dk> dateSun 19 Nov 2017, 15:37 (9 years ago) parent1855f8becce09c
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--------------------------------------------------------------------------------