split 0.1.2.1 → 0.1.2.2
raw patch · 3 files changed
+36/−10 lines, 3 files
Files
- CHANGES +7/−0
- Data/List/Split/Internals.hs +27/−8
- split.cabal +2/−2
+ CHANGES view
@@ -0,0 +1,7 @@+* 0.1.2.2++ - Fix typo in documentation (davidL)++ - Lazier implementation of splitInternal from Jan Christiansen.+ Performance on large lists with not very many split points is now+ greatly improved.
Data/List/Split/Internals.hs view
@@ -138,14 +138,33 @@ -- ('splitInternal' d l) == l@. splitInternal :: Delimiter a -> [a] -> SplitList a splitInternal _ [] = []-splitInternal d xxs@(x:xs) = case matchDelim d xxs of- -- special case for blank delimiter- Just ([], (r:rs)) -> Delim [] : Text [r] : splitInternal d rs- Just (match,rest) -> Delim match : splitInternal d rest- _ -> x `consText` splitInternal d xs- where consText z (Text c : ys) = Text (z:c) : ys- consText z ys = Text [z] : ys+splitInternal d xxs+ | null xs = toSplitList match+ | otherwise = Text xs : toSplitList match+ where+ (xs,match) = breakDelim d xxs + toSplitList Nothing = []+ toSplitList (Just ([],r:rs)) = Delim [] : Text [r] : splitInternal d rs+ toSplitList (Just (delim,rest)) = Delim delim : splitInternal d rest++breakDelim :: Delimiter a -> [a] -> ([a],Maybe ([a],[a]))+breakDelim d@(DelimEltPred p) (x:xs)+ | p x = ([],Just ([x],xs))+ | otherwise = let (ys,match) = breakDelim d xs in (x:ys,match)+breakDelim (DelimEltPred _) [] = ([],Nothing)+breakDelim (DelimSublist []) xs = ([],Just ([],xs))+breakDelim (DelimSublist _) [] = ([],Nothing)+breakDelim (DelimSublist ds) xxs@(x:xs) =+ case matchSublist ds xxs of+ Nothing -> let (ys,match) = breakDelim (DelimSublist ds) xs in (x:ys,match)+ Just rest -> ([],Just (ds,rest))++matchSublist :: Eq a => [a] -> [a] -> Maybe [a]+matchSublist [] xs = Just xs+matchSublist _ [] = Nothing+matchSublist (d:ds) (x:xs) = if d==x then matchSublist ds xs else Nothing+ -- | Given a split list in the internal tagged representation, produce -- a new internal tagged representation corresponding to the final -- output, according to the strategy defined by the given@@ -329,7 +348,7 @@ -- Equivalent to @'dropInitBlank' . 'keepDelimsL' . 'onSublist'@. -- For example: ----- > split (startsWith "app") "applyappicativeapplaudapproachapple" == ["apply","appicative","applaud","approach","apple"]+-- > split (startsWith "app") "applyapplicativeapplaudapproachapple" == ["apply","applicative","applaud","approach","apple"] startsWith :: Eq a => [a] -> Splitter a startsWith = dropInitBlank . keepDelimsL . onSublist
split.cabal view
@@ -1,12 +1,12 @@ Name: split-Version: 0.1.2.1+Version: 0.1.2.2 Stability: experimental Description: Combinator library and utility functions for splitting lists. Homepage: http://code.haskell.org/~byorgey/code/split Synopsis: Combinator library for splitting lists. License: BSD3 License-file: LICENSE-Extra-source-files: README, Properties.hs+Extra-source-files: README, Properties.hs, CHANGES Author: Brent Yorgey Maintainer: byorgey@cis.upenn.edu Category: List