hx 0.1 → 0.2
raw patch · 2 files changed
+39/−2 lines, 2 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Haskell.X: count1 :: [a] -> Int
+ Haskell.X: count2 :: [[a]] -> Int
+ Haskell.X: count3 :: [[[a]]] -> Int
+ Haskell.X: count4 :: [[[[a]]]] -> Int
+ Haskell.X: segment2 :: Int -> [[a]] -> [[a]]
+ Haskell.X: segment3 :: Int -> [[[a]]] -> [[a]]
Files
- hx.cabal +1/−1
- src/Haskell/X.hs +38/−1
hx.cabal view
@@ -1,5 +1,5 @@ Name: hx-Version: 0.1+Version: 0.2 Synopsis: Utility functions that some may feel are missing from Prelude and base. Description: Utility functions that some may feel are missing from Prelude and base. .
src/Haskell/X.hs view
@@ -1,4 +1,4 @@-{-# LANGUAGE Haskell2010 #-}+{-# LANGUAGE Haskell2010, FlexibleInstances, OverlappingInstances #-} {-# OPTIONS -Wall #-} module Haskell.X where@@ -56,4 +56,41 @@ | x == n = r : tr n r xs | otherwise = x : tr n r xs tr _ _ [] = []++-- | Counts how many elements there are in a 4 levels deep list.+count4 :: [[[[a]]]] -> Int+count4 = sum . map (sum . map (sum . map length))++-- | Counts how many elements there are in a 3 levels deep list.+count3 :: [[[a]]] -> Int+count3 = sum . map (sum . map length)++-- | Counts how many elements there are in a 2 levels deep list.+count2 :: [[a]] -> Int+count2 = sum . map length++-- | Counts how many elements there are in a 1 level deep list.+count1 :: [a] -> Int+count1 = length++-- | Segments the elements of a 3 levels deep list such that+-- the segments contain at least the specified amount of elements,+-- without breaking apart any subsegments.+segment3 :: Int -> [[[a]]] -> [[a]]+segment3 _ [] = []+segment3 size as = concatMap concat segment : segment3 size rest+ where+ segmentations = zip (inits as) (tails as)+ (segment, rest) = head $ dropWhile ((< size) . count3 . fst) segmentations++-- | Segments the elements of a 2 levels deep list such that+-- the segments contain at least the specified amount of elements,+-- without breaking apart any subsegments.+segment2 :: Int -> [[a]] -> [[a]]+segment2 _ [] = []+segment2 size as = concat segment : segment2 size rest+ where+ segmentations = zip (inits as) (tails as)+ (segment, rest) = head $ dropWhile ((< size) . count2 . fst) segmentations+