Bryan O'Sullivan avatar Bryan O'Sullivan committed dae5e2d

Implement and test lazy scanr1

Comments (0)

Files changed (2)


     , scanl
     , scanl1
     , scanr
-    -- , scanr1
+    , scanr1
     -- ** Accumulating maps
     , mapAccumL
 scanr :: (Char -> Char -> Char) -> Char -> Text -> Text
 scanr f v = reverse . scanl (flip f) v . reverse
+-- | /O(n)/ 'scanr1' is a variant of 'scanr' that has no starting
+-- value argument.
+scanr1 :: (Char -> Char -> Char) -> Text -> Text
+scanr1 f t | null t    = empty
+           | otherwise = scanr f (last t) (init t)
 -- | /O(n)/ Like a combination of 'map' and 'foldl'. Applies a
 -- function to each element of a 'Text', passing an accumulating
 -- parameter from left to right, and returns a final 'Text'.


 prop_T_scanr f z       = L.scanr f z   `eqP`  (unpackT . T.scanr f z)
 prop_TL_scanr f z      = L.scanr f z   `eqP`  (unpackT . TL.scanr f z)
 prop_T_scanr1 f        = L.scanr1 f    `eqP`  (unpackT . T.scanr1 f)
+prop_TL_scanr1 f       = L.scanr1 f    `eqP`  (unpackT . TL.scanr1 f)
 prop_T_mapAccumL f z   = L.mapAccumL f z `eqP` (second unpackT . T.mapAccumL f z)
     where types = f :: Int -> Char -> (Int,Char)
   ("prop_T_scanr", mytest prop_T_scanr),
   ("prop_TL_scanr", mytest prop_TL_scanr),
   ("prop_T_scanr1", mytest prop_T_scanr1),
+  ("prop_TL_scanr1", mytest prop_TL_scanr1),
   ("prop_T_mapAccumL", mytest prop_T_mapAccumL),
   ("prop_TL_mapAccumL", mytest prop_TL_mapAccumL),
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.