on master help sign in
Implement and test scanl1

--HG-- extra : convert_revision : b9d9328622e3bef8ac11f2af08f39e702f0c5b14

commit7541131a2a58af0a21ac203d00614f7b0716678f authorBryan O'Sullivan <bos@serpentine.com> dateTue 3 Feb 2009, 22:33 (18 years ago) parent8ba69d7
2 files changed+12−1
Data/Text.hs+10−1 tests/Properties.hs+2
Data/Text.hs+10−1
@@ -75,7 +75,7 @@ module Data.Text
7575
7676 -- ** Scans
7777 , scanl
78− -- , scanl1
78+ , scanl1
7979 -- , scanr
8080 -- , scanr1
8181
@@ -495,6 +495,15 @@ scanl :: (Char -> Char -> Char) -> Char -> Text -> Text
495495scanl f z t = unstream (S.scanl f z (stream t))
496496{-# INLINE scanl #-}
497497
498+-- | /O(n)/ 'scanl1' is a variant of 'scanl' that has no starting
499+-- value argument. This function is subject to array fusion.
500+--
501+-- > scanl1 f [x1, x2, ...] == [x1, x1 `f` x2, ...]
502+scanl1 :: (Char -> Char -> Char) -> Text -> Text
503+scanl1 f t | null t = empty
504+ | otherwise = scanl f (head t) (tail t)
505+{-# INLINE scanl1 #-}
506+
498507-- -----------------------------------------------------------------------------
499508-- ** Generating and unfolding 'Text's
500509
tests/Properties.hs+2
@@ -72,6 +72,7 @@ prop_maximum = L.maximum `eqEP` T.maximum
7272prop_minimum = L.minimum `eqEP` T.minimum
7373
7474prop_scanl f z = L.scanl f z `eqP` (unpack . T.scanl f z)
75+prop_scanl1 f = L.scanl1 f `eqP` (unpack . T.scanl1 f)
7576
7677prop_replicate n = L.replicate n `eq` (unpack . T.replicate n)
7778prop_unfoldr n = L.unfoldr f `eq` (unpack . T.unfoldr f)
@@ -159,6 +160,7 @@ tests = [
159160 ("prop_minimum", mytest prop_minimum),
160161
161162 ("prop_scanl", mytest prop_scanl),
163+ ("prop_scanl1", mytest prop_scanl1),
162164
163165 ("prop_replicate", mytest prop_replicate),
164166 ("prop_unfoldr", mytest prop_unfoldr),