Repository : ssh://darcs.haskell.org//srv/darcs/packages/base On branch : master
http://hackage.haskell.org/trac/ghc/changeset/216cfb1969238b403fec5e08f4bf1f8a8772734b >--------------------------------------------------------------- commit 216cfb1969238b403fec5e08f4bf1f8a8772734b Author: Simon Marlow <[email protected]> Date: Mon Nov 14 12:40:03 2011 +0000 Add "dropWhileEnd", as discussed on the libraries list >--------------------------------------------------------------- Data/List.hs | 11 +++++++++++ 1 files changed, 11 insertions(+), 0 deletions(-) diff --git a/Data/List.hs b/Data/List.hs index 4edd9eb..55e3dd2 100644 --- a/Data/List.hs +++ b/Data/List.hs @@ -95,6 +95,7 @@ module Data.List , takeWhile -- :: (a -> Bool) -> [a] -> [a] , dropWhile -- :: (a -> Bool) -> [a] -> [a] + , dropWhileEnd -- :: (a -> Bool) -> [a] -> [a] , span -- :: (a -> Bool) -> [a] -> ([a], [a]) , break -- :: (a -> Bool) -> [a] -> ([a], [a]) @@ -228,6 +229,16 @@ infix 5 \\ -- comment to fool cpp -- ----------------------------------------------------------------------------- -- List functions +-- | The 'dropWhileEnd' function drops the largest suffix of a list +-- in which the given predicate holds for all elements. For example: +-- +-- > dropWhileEnd isSpace "foo\n" == "foo" +-- > dropWhileEnd isSpace "foo bar" == "foo bar" +-- > dropWhileEnd isSpace ("foo\n" ++ undefined) == "foo" ++ undefined + +dropWhileEnd :: (a -> Bool) -> [a] -> [a] +dropWhileEnd p = foldr (\x xs -> if p x && null xs then [] else x : xs) [] + -- | The 'stripPrefix' function drops the given prefix from a list. -- It returns 'Nothing' if the list did not start with the prefix -- given, or 'Just' the list after the prefix, if it does. _______________________________________________ Cvs-libraries mailing list [email protected] http://www.haskell.org/mailman/listinfo/cvs-libraries
