split 0.1.3 → 0.1.4
raw patch · 5 files changed
+40/−1 lines, 5 files
Files
- CHANGES +6/−0
- Data/List/Split.hs +1/−0
- Data/List/Split/Internals.hs +16/−0
- Properties.hs +16/−0
- split.cabal +1/−1
CHANGES view
@@ -1,3 +1,9 @@+* 0.1.4++ - Add 'splitPlacesBlanks' function from Daniel Wagner; like+ 'splitPlaces' but pads the output with blank lists to match the+ length of the input list of places to split.+ * 0.1.3 - Add 'chop' list-processing function.
Data/List/Split.hs view
@@ -46,6 +46,7 @@ , splitEvery , chunk , splitPlaces+ , splitPlacesBlanks , chop -- * Splitting combinators
Data/List/Split/Internals.hs view
@@ -487,6 +487,7 @@ -- -- > splitPlaces [2,3,4] [1..20] == [[1,2],[3,4,5],[6,7,8,9]] -- > splitPlaces [4,9] [1..10] == [[1,2,3,4],[5,6,7,8,9,10]]+-- > splitPlaces [4,9,3] [1..10] == [[1,2,3,4],[5,6,7,8,9,10]] -- -- The behavior of @'splitPlaces' ls xs@ when @'sum' ls /= 'length' xs@ can -- be inferred from the above examples and the fact that 'splitPlaces'@@ -497,6 +498,21 @@ => [i] -> [b] -> ([b] -> t -> t) -> t -> t splitPlacer [] _ _ n = n splitPlacer _ [] _ n = n+ splitPlacer (l:ls) xs c n = let (x1, x2) = genericSplitAt l xs+ in x1 `c` splitPlacer ls x2 c n++-- | Split a list into chunks of the given lengths. Unlike 'splitPlaces', the+-- output list will always be the same length as the first input argument. For+-- example:+--+-- > splitPlacesBlanks [2,3,4] [1..20] == [[1,2],[3,4,5],[6,7,8,9]]+-- > splitPlacesBlanks [4,9] [1..10] == [[1,2,3,4],[5,6,7,8,9,10]]+-- > splitPlacesBlanks [4,9,3] [1..10] == [[1,2,3,4],[5,6,7,8,9,10],[]]+splitPlacesBlanks :: Integral a => [a] -> [e] -> [[e]]+splitPlacesBlanks is ys = build (splitPlacer is ys) where+ splitPlacer :: forall i b t. Integral i+ => [i] -> [b] -> ([b] -> t -> t) -> t -> t+ splitPlacer [] _ _ n = n splitPlacer (l:ls) xs c n = let (x1, x2) = genericSplitAt l xs in x1 `c` splitPlacer ls x2 c n
Properties.hs view
@@ -105,6 +105,9 @@ , ("splitPlaces/last <= n", qc prop_splitPlaces_last_less_n) , ("splitPlaces/preserve", qc prop_splitPlaces_preserve) , ("splitPlaces/splitEvery", qc prop_splitPlaces_splitEvery)+ , ("splitPlacesB/length", qc prop_splitPlacesB_length)+ , ("splitPlacesB/last <= n", qc prop_splitPlacesB_last_less_n)+ , ("splitPlacesB/preserve", qc prop_splitPlacesB_preserve) , ("lines", qc prop_lines) , ("wordsBy/words", qc prop_wordsBy_words) , ("linesBy/lines", qc prop_linesBy_lines)@@ -290,6 +293,19 @@ prop_splitPlaces_splitEvery :: Positive Int -> [Elt] -> Bool prop_splitPlaces_splitEvery (Positive n) l = splitPlaces (repeat n) l == splitEvery n l++prop_splitPlacesB_length :: [NonNegative Int] -> [Elt] -> Bool+prop_splitPlacesB_length ps xs = length ps' == length (splitPlacesBlanks ps' xs)+ where ps' = map unNN ps++prop_splitPlacesB_last_less_n :: NonEmptyList (NonNegative Int) -> NonEmptyList Elt -> Bool+prop_splitPlacesB_last_less_n (NonEmpty ps) (NonEmpty l) = (head $ drop (length l' - 1) ps') >= length (last l')+ where l' = splitPlacesBlanks ps' l+ ps' = map unNN ps++prop_splitPlacesB_preserve :: [NonNegative Integer] -> [Elt] -> Bool+prop_splitPlacesB_preserve ps l = concat (splitPlacesBlanks ps' l) == genericTake (sum ps') l+ where ps' = map unNN ps unNN :: NonNegative a -> a unNN (NonNegative x) = x
split.cabal view
@@ -1,5 +1,5 @@ Name: split-Version: 0.1.3+Version: 0.1.4 Stability: stable Description: Combinator library and utility functions for splitting lists. Homepage: http://code.haskell.org/~byorgey/code/split