packages feed

grouped-list 0.2.0.0 → 0.2.1.0

raw patch · 3 files changed

+35/−2 lines, 3 files

Files

Data/GroupedList.hs view
@@ -38,6 +38,9 @@   , filter     -- * Sorting   , sort+    -- * Zipping+  , zipWith+  , zip     -- * List conversion     -- | For to-list conversion use 'toList'.   , fromList@@ -54,7 +57,8 @@  import Prelude hiding   ( concat, concatMap, replicate, filter, map-  , take, drop, foldl, foldr, length+  , take, drop, foldl, foldr, length, zipWith+  , zip     ) import qualified Prelude as Prelude import Data.Pointed@@ -466,3 +470,30 @@ traverseGroupedByGroupAccum f acc0 (Grouped gs) = foldrM go (acc0, mempty) gs   where     go g (acc, gd) = second (<> gd) <$> f acc g++------------------------------------------------------------------+------------------------------------------------------------------+-- Zipping++-- | Combine two lists using a combining function. If one list is longer,+--   remaining elements are discarded.+zipWith :: Eq c => (a -> b -> c) -> Grouped a -> Grouped b -> Grouped c+zipWith f (Grouped xs) (Grouped ys) = fold $ fmap fromGroup $ go xs ys+  where+    go gs gs' =+      case S.viewl gs of+        Group n x S.:< hs ->+          case S.viewl gs' of+            Group m y S.:< hs' ->+              let z = f x y+              in  case () of+                    _ | n == m -> Group n z : go hs hs'+                    _ | n  > m -> Group m z : go (Group (n-m) x S.<| hs) hs'+                    _ -> Group n z : go hs (Group (m-n) y S.<| hs')+            _ -> []+        _ -> []++-- | Combine two lists in a single list of pairs. If one list is longer,+--   remaining elements are discarded.+zip :: (Eq a, Eq b) => Grouped a -> Grouped b -> Grouped (a,b)+zip = zipWith (,)
grouped-list.cabal view
@@ -1,5 +1,5 @@ name:                grouped-list-version:             0.2.0.0+version:             0.2.1.0 synopsis:            Grouped lists. Equal consecutive elements are grouped. description:   Grouped lists work like regular lists, except for two conditions:
test/examples.hs view
@@ -57,3 +57,5 @@     =: [1,1,2,2]   GL.sort [3,2,1,3]     =: [1,2,3,3]+  GL.zipWith (+) [1,2,1,1] [2,1,1,2]+    =: [3,3,2,3]