Commits

Bryan O'Sullivan  committed a3d8ac0

Implement scanl

  • Participants
  • Parent commits ac8b3c1

Comments (0)

Files changed (2)

File Data/Text.hs

     , minimum
 
     -- * Construction
+
+    -- ** Scans
+    , scanl
+
+    -- ** Generation and unfolding
     , replicate
     , unfoldr
     , unfoldrN
 -- -----------------------------------------------------------------------------
 -- * Building 'Text's
 
+scanl :: (Char -> Char -> Char) -> Char -> Text -> Text
+scanl f z t = unstream (S.scanl f z (stream t))
+{-# INLINE scanl #-}
+
 -- -----------------------------------------------------------------------------
 -- ** Generating and unfolding 'Text's
 

File Data/Text/Fusion.hs

     , minimum
 
     -- * Construction
+    -- ** Scans
+    , scanl
+
+    -- ** Generation and unfolding
     , replicate
     , unfoldr
     , unfoldrN
 -- -----------------------------------------------------------------------------
 -- * Building streams
 
+scanl :: (Char -> Char -> Char) -> Char -> Stream Char -> Stream Char
+scanl f z0 (Stream next0 s0 len) = Stream next (S1 :!: z0 :!: s0) (len+1)
+  where
+    {-# INLINE next #-}
+    next (S1 :!: z :!: s) = Yield z (S2 :!: z :!: s)
+    next (S2 :!: z :!: s) = case next0 s of
+                              Yield x s' -> let !x' = f z x
+                                            in Yield x' (S2 :!: x' :!: s')
+                              Skip s'    -> Skip (S2 :!: z :!: s')
+                              Done       -> Done
+{-# INLINE [0] scanl #-}
+
 -- -----------------------------------------------------------------------------
 -- ** Generating and unfolding streams