1. Bryan O'Sullivan
  2. text

Commits

Bryan O'Sullivan  committed cb869df

Implement and test scanl1

  • Participants
  • Parent commits f9bdb23
  • Branches default

Comments (0)

Files changed (2)

File Data/Text.hs

View file
 
     -- ** Scans
     , scanl
-    -- , scanl1
+    , scanl1
     -- , scanr
     -- , scanr1
 
 scanl f z t = unstream (S.scanl f z (stream t))
 {-# INLINE scanl #-}
 
+-- | /O(n)/ 'scanl1' is a variant of 'scanl' that has no starting
+-- value argument.  This function is subject to array fusion.
+--
+-- > scanl1 f [x1, x2, ...] == [x1, x1 `f` x2, ...]
+scanl1 :: (Char -> Char -> Char) -> Text -> Text
+scanl1 f t | null t    = empty
+           | otherwise = scanl f (head t) (tail t)
+{-# INLINE scanl1 #-}
+
 -- -----------------------------------------------------------------------------
 -- ** Generating and unfolding 'Text's
 

File tests/Properties.hs

View file
 prop_minimum         = L.minimum     `eqEP` T.minimum
 
 prop_scanl f z       = L.scanl f z   `eqP`  (unpack . T.scanl f z)
+prop_scanl1 f        = L.scanl1 f    `eqP`  (unpack . T.scanl1 f)
 
 prop_replicate n     = L.replicate n `eq`   (unpack . T.replicate n)
 prop_unfoldr n       = L.unfoldr f   `eq`   (unpack . T.unfoldr f)
   ("prop_minimum", mytest prop_minimum),
 
   ("prop_scanl", mytest prop_scanl),
+  ("prop_scanl1", mytest prop_scanl1),
 
   ("prop_replicate", mytest prop_replicate),
   ("prop_unfoldr", mytest prop_unfoldr),