Bryan O'Sullivan avatar Bryan O'Sullivan committed 47b3cc0

Rename dropAfter to dropWhileEnd.

Comments (0)

Files changed (2)

     , drop
     , takeWhile
     , dropWhile
-    , dropAfter
+    , dropWhileEnd
     , dropAround
     , strip
     , stripLeft
     unstream (S.dropWhile p (stream t)) = dropWhile p t
   #-}
 
--- | /O(n)/ 'dropAfter' @p@ @t@ returns the prefix remaining after
+-- | /O(n)/ 'dropWhileEnd' @p@ @t@ returns the prefix remaining after
 -- dropping characters that fail the predicate @p@ from the end of
--- @t@.  This function is subject to array fusion.
-dropAfter :: (Char -> Bool) -> Text -> Text
-dropAfter p t@(Text arr off len) = loop (len-1) len
+-- @t@.  Subject to fusion.
+-- Examples:
+--
+-- > dropWhileEnd (=='.') "foo..." == "foo"
+dropWhileEnd :: (Char -> Bool) -> Text -> Text
+dropWhileEnd p t@(Text arr off len) = loop (len-1) len
   where loop !i !l | l <= 0    = empty
                    | p c       = loop (i+d) (l+d)
                    | otherwise = Text arr off l
             where (c,d)        = reverseIter t i
-{-# INLINE [1] dropAfter #-}
+{-# INLINE [1] dropWhileEnd #-}
 
 {-# RULES
-"TEXT dropAfter -> fused" [~1] forall p t.
-    dropAfter p t = S.reverse (S.dropWhile p (S.reverseStream t))
-"TEXT dropAfter -> unfused" [1] forall p t.
-    S.reverse (S.dropWhile p (S.reverseStream t)) = dropAfter p t
+"TEXT dropWhileEnd -> fused" [~1] forall p t.
+    dropWhileEnd p t = S.reverse (S.dropWhile p (S.reverseStream t))
+"TEXT dropWhileEnd -> unfused" [1] forall p t.
+    S.reverse (S.dropWhile p (S.reverseStream t)) = dropWhileEnd p t
   #-}
 
 -- | /O(n)/ 'dropAround' @p@ @t@ returns the substring remaining after
 -- dropping characters that fail the predicate @p@ from both the
 -- beginning and end of @t@.  Subject to fusion.
 dropAround :: (Char -> Bool) -> Text -> Text
-dropAround p = dropWhile p . dropAfter p
+dropAround p = dropWhile p . dropWhileEnd p
 {-# INLINE [1] dropAround #-}
 
 -- | /O(n)/ Remove leading white space from a string.  Equivalent to:
 
 -- | /O(n)/ Remove trailing white space from a string.  Equivalent to:
 --
--- > dropAfter isSpace
+-- > dropWhileEnd isSpace
 stripRight :: Text -> Text
-stripRight = dropAfter isSpace
+stripRight = dropWhileEnd isSpace
 {-# INLINE [1] stripRight #-}
 
 -- | /O(n)/ Remove leading and trailing white space from a string.

tests/Properties.hs

 prop_S_dropWhile p     = L.dropWhile p `eqP` (unpackS . S.dropWhile p)
 prop_T_dropWhile p     = L.dropWhile p `eqP` (unpackS . T.dropWhile p)
 prop_TL_dropWhile p    = L.dropWhile p `eqP` (unpackS . S.dropWhile p)
-prop_S_dropAfter p     = T.dropAfter p `eq` (S.reverse . S.dropWhile p . S.reverseStream)
-prop_T_dropAfter p     = (T.reverse . T.dropWhile p . T.reverse) `eq` T.dropAfter p
-prop_T_dropAround p    = (T.dropWhile p . T.dropAfter p) `eq` T.dropAround p
+prop_S_dropWhileEnd p  = T.dropWhileEnd p `eq` (S.reverse . S.dropWhile p . S.reverseStream)
+prop_T_dropWhileEnd p  = (T.reverse . T.dropWhile p . T.reverse) `eq` T.dropWhileEnd p
+prop_T_dropAround p    = (T.dropWhile p . T.dropWhileEnd p) `eq` T.dropAround p
 prop_T_stripLeft       = T.dropWhile isSpace `eq` T.stripLeft
-prop_T_stripRight      = T.dropAfter isSpace `eq` T.stripRight
+prop_T_stripRight      = T.dropWhileEnd isSpace `eq` T.stripRight
 prop_T_strip           = T.dropAround isSpace `eq` T.strip
 prop_T_splitAt n       = L.splitAt n   `eqP` (unpack2 . T.splitAt n)
 prop_TL_splitAt n      = L.splitAt n   `eqP` (unpack2 . TL.splitAt (fromIntegral n))
   ("prop_S_dropWhile", mytest prop_S_dropWhile),
   ("prop_T_dropWhile", mytest prop_T_dropWhile),
   ("prop_TL_dropWhile", mytest prop_TL_dropWhile),
-  ("prop_S_dropAfter", mytest prop_S_dropAfter),
-  ("prop_T_dropAfter", mytest prop_T_dropAfter),
+  ("prop_S_dropWhileEnd", mytest prop_S_dropWhileEnd),
+  ("prop_T_dropWhileEnd", mytest prop_T_dropWhileEnd),
   ("prop_T_dropAround", mytest prop_T_dropAround),
   ("prop_T_stripLeft", mytest prop_T_stripLeft),
   ("prop_T_stripRight", mytest prop_T_stripRight),
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 ProjectModifiedEvent.java.
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.