Hello community, here is the log from the commit of package ghc-foldl for openSUSE:Factory checked in at 2020-07-09 13:19:13 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/ghc-foldl (Old) and /work/SRC/openSUSE:Factory/.ghc-foldl.new.3060 (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "ghc-foldl" Thu Jul 9 13:19:13 2020 rev:10 rq:819575 version:1.4.7 Changes: -------- --- /work/SRC/openSUSE:Factory/ghc-foldl/ghc-foldl.changes 2020-06-19 17:12:53.718052841 +0200 +++ /work/SRC/openSUSE:Factory/.ghc-foldl.new.3060/ghc-foldl.changes 2020-07-09 13:19:38.037320126 +0200 @@ -1,0 +2,8 @@ +Sun Jun 21 02:00:43 UTC 2020 - [email protected] + +- Update foldl to version 1.4.7. + 1.4.7 + + * Add `foldByKey{,Hash}Map` functions + +------------------------------------------------------------------- Old: ---- foldl-1.4.6.tar.gz New: ---- foldl-1.4.7.tar.gz ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ ghc-foldl.spec ++++++ --- /var/tmp/diff_new_pack.tV88MH/_old 2020-07-09 13:19:39.013323211 +0200 +++ /var/tmp/diff_new_pack.tV88MH/_new 2020-07-09 13:19:39.013323211 +0200 @@ -19,7 +19,7 @@ %global pkg_name foldl %bcond_with tests Name: ghc-%{pkg_name} -Version: 1.4.6 +Version: 1.4.7 Release: 0 Summary: Composable, streaming, and efficient left folds License: BSD-3-Clause ++++++ foldl-1.4.6.tar.gz -> foldl-1.4.7.tar.gz ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/foldl-1.4.6/CHANGELOG.md new/foldl-1.4.7/CHANGELOG.md --- old/foldl-1.4.6/CHANGELOG.md 2001-09-09 03:46:40.000000000 +0200 +++ new/foldl-1.4.7/CHANGELOG.md 2020-06-19 17:47:18.000000000 +0200 @@ -1,3 +1,7 @@ +1.4.7 + +* Add `foldByKey{,Hash}Map` functions + 1.4.6 * Add `nest`/`predropWhile`/`drop`/`dropM` diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/foldl-1.4.6/foldl.cabal new/foldl-1.4.7/foldl.cabal --- old/foldl-1.4.6/foldl.cabal 2001-09-09 03:46:40.000000000 +0200 +++ new/foldl-1.4.7/foldl.cabal 2020-06-19 17:47:18.000000000 +0200 @@ -1,6 +1,6 @@ Name: foldl -Version: 1.4.6 -Cabal-Version: >=1.8.0.2 +Version: 1.4.7 +Cabal-Version: >=1.10 Build-Type: Simple License: BSD3 License-File: LICENSE @@ -49,6 +49,7 @@ Control.Foldl.Optics Control.Foldl.Internal GHC-Options: -O2 -Wall + Default-Language: Haskell2010 Benchmark benchmarks Type: exitcode-stdio-1.0 @@ -59,6 +60,7 @@ criterion, foldl GHC-Options: -O2 -Wall -rtsopts -rtsopts -with-rtsopts=-T + Default-Language: Haskell2010 Test-Suite doctest Type: exitcode-stdio-1.0 @@ -68,3 +70,4 @@ base, doctest >= 0.16 GHC-Options: -threaded + Default-Language: Haskell2010 diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/foldl-1.4.6/src/Control/Foldl.hs new/foldl-1.4.7/src/Control/Foldl.hs --- old/foldl-1.4.6/src/Control/Foldl.hs 2001-09-09 03:46:40.000000000 +0200 +++ new/foldl-1.4.7/src/Control/Foldl.hs 2020-06-19 17:47:18.000000000 +0200 @@ -39,6 +39,7 @@ {-# LANGUAGE ExistentialQuantification #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE RankNTypes #-} +{-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE Trustworthy #-} module Control.Foldl ( @@ -99,7 +100,9 @@ , set , hashSet , map + , foldByKeyMap , hashMap + , foldByKeyHashMap , vector , vectorM @@ -151,6 +154,7 @@ import Data.Foldable (Foldable) import Data.Functor.Identity (Identity, runIdentity) import Data.Functor.Contravariant (Contravariant(..)) +import Data.HashMap.Strict (HashMap) import Data.Map.Strict (Map, alter) import Data.Maybe (fromMaybe) import Data.Monoid hiding ((<>)) @@ -940,6 +944,28 @@ done = id {-# INLINABLE map #-} + +{- | Given a 'Fold', produces a 'Map' which applies that fold to each @a@ separated by key @k@. + +>>> fold (foldByKeyMap Control.Foldl.sum) [("a",1), ("b",2), ("b",20), ("a",10)] +fromList [("a",11),("b",22)] +-} +foldByKeyMap :: forall k a b. Ord k => Fold a b -> Fold (k, a) (Map k b) +foldByKeyMap f = case f of + Fold (step0 :: x -> a -> x) (ini0 :: x) (end0 :: x -> b) -> + let + step :: Map k x -> (k,a) -> Map k x + step mp (k,a) = Map.alter addToMap k mp where + addToMap Nothing = Just $ step0 ini0 a + addToMap (Just existing) = Just $ step0 existing a + + ini :: Map k x + ini = Map.empty + + end :: Map k x -> Map k b + end = fmap end0 + in Fold step ini end where + {-| Fold pairs into a hash-map. -} @@ -951,6 +977,27 @@ done = id {-# INLINABLE hashMap #-} +{- | Given a 'Fold', produces a 'HashMap' which applies that fold to each @a@ separated by key @k@. + +>>> fold (foldByKeyHashMap Control.Foldl.sum) [("a",1), ("b",2), ("b",20), ("a",10)] +fromList [("a",11),("b",22)] +-} +foldByKeyHashMap :: forall k a b. (Hashable k, Eq k) => Fold a b -> Fold (k, a) (HashMap k b) +foldByKeyHashMap f = case f of + Fold (step0 :: x -> a -> x) (ini0 :: x) (end0 :: x -> b) -> + let + step :: HashMap k x -> (k,a) -> HashMap k x + step mp (k,a) = HashMap.alter addToHashMap k mp where + addToHashMap Nothing = Just $ step0 ini0 a + addToHashMap (Just existing) = Just $ step0 existing a + + ini :: HashMap k x + ini = HashMap.empty + + end :: HashMap k x -> HashMap k b + end = fmap end0 + in Fold step ini end where + -- | Fold all values into a vector vector :: Vector v a => Fold a (v a) vector = Fold step begin done
