From d8926d9491d6bd04a1abd5e145729373814b080c Mon Sep 17 00:00:00 2001 From: L0neGamer Date: Fri, 12 Jul 2024 19:02:40 +0100 Subject: [PATCH 1/4] add dist-newstyle to .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 67475176..f6b8b181 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ cabal.sandbox.config .stack-work/ tarballs/ *~ +dist-newstyle/ From df446ef6a377a88e8fc22dbc805f9c7788577b96 Mon Sep 17 00:00:00 2001 From: L0neGamer Date: Fri, 12 Jul 2024 19:04:31 +0100 Subject: [PATCH 2/4] add filterWithKey to IsMap, change definition of filterMap to use filterWithKey, add better definitions of filterWithKey to instances in file #218 --- mono-traversable/src/Data/Containers.hs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/mono-traversable/src/Data/Containers.hs b/mono-traversable/src/Data/Containers.hs index 31322e8a..468e824a 100644 --- a/mono-traversable/src/Data/Containers.hs +++ b/mono-traversable/src/Data/Containers.hs @@ -548,8 +548,15 @@ class (MonoTraversable map, SetContainer map) => IsMap map where -- | Filter values in a map. -- -- @since 1.0.9.0 - filterMap :: IsMap map => (MapValue map -> Bool) -> map -> map - filterMap p = mapFromList . filter (p . snd) . mapToList + filterMap :: (MapValue map -> Bool) -> map -> map + filterMap = filterWithKey . const + + -- | Equivalent to 'filterMap', but the function accepts the key, + -- as well as the value. + -- + -- @since 1.0.?? + filterWithKey :: (ContainerKey map -> MapValue map -> Bool) -> map -> map + filterWithKey p = mapFromList . filter (uncurry p) . mapToList -- | This instance uses the functions from "Data.Map.Strict". instance Ord key => IsMap (Map.Map key value) where @@ -599,6 +606,8 @@ instance Ord key => IsMap (Map.Map key value) where {-# INLINE omapKeysWith #-} filterMap = Map.filter {-# INLINE filterMap #-} + filterWithKey = Map.filterWithKey + {-# INLINE filterWithKey #-} -- | This instance uses the functions from "Data.HashMap.Strict". instance (Eq key, Hashable key) => IsMap (HashMap.HashMap key value) where @@ -636,6 +645,8 @@ instance (Eq key, Hashable key) => IsMap (HashMap.HashMap key value) where --mapKeysWith = HashMap.mapKeysWith filterMap = HashMap.filter {-# INLINE filterMap #-} + filterWithKey = HashMap.filterWithKey + {-# INLINE filterWithKey #-} -- | This instance uses the functions from "Data.IntMap.Strict". instance IsMap (IntMap.IntMap value) where @@ -684,6 +695,8 @@ instance IsMap (IntMap.IntMap value) where {-# INLINE omapKeysWith #-} filterMap = IntMap.filter {-# INLINE filterMap #-} + filterWithKey = IntMap.filterWithKey + {-# INLINE filterWithKey #-} instance Eq key => IsMap [(key, value)] where type MapValue [(key, value)] = value From d1b1341ed8d0a98395987c12ce9acbb7691981c7 Mon Sep 17 00:00:00 2001 From: L0neGamer Date: Fri, 12 Jul 2024 19:13:48 +0100 Subject: [PATCH 3/4] set version of mono-traversable --- mono-traversable/mono-traversable.cabal | 2 +- mono-traversable/package.yaml | 2 +- mono-traversable/src/Data/Containers.hs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/mono-traversable/mono-traversable.cabal b/mono-traversable/mono-traversable.cabal index 5e8710dd..f2b53864 100644 --- a/mono-traversable/mono-traversable.cabal +++ b/mono-traversable/mono-traversable.cabal @@ -5,7 +5,7 @@ cabal-version: 1.12 -- see: https://github.com/sol/hpack name: mono-traversable -version: 1.0.18.0 +version: 1.0.19.0 synopsis: Type classes for mapping, folding, and traversing monomorphic containers description: Please see the README at category: Data diff --git a/mono-traversable/package.yaml b/mono-traversable/package.yaml index d8a68e4f..0bae5d63 100644 --- a/mono-traversable/package.yaml +++ b/mono-traversable/package.yaml @@ -1,5 +1,5 @@ name: mono-traversable -version: 1.0.18.0 +version: 1.0.19.0 synopsis: Type classes for mapping, folding, and traversing monomorphic containers description: Please see the README at category: Data diff --git a/mono-traversable/src/Data/Containers.hs b/mono-traversable/src/Data/Containers.hs index 468e824a..1dd58017 100644 --- a/mono-traversable/src/Data/Containers.hs +++ b/mono-traversable/src/Data/Containers.hs @@ -554,7 +554,7 @@ class (MonoTraversable map, SetContainer map) => IsMap map where -- | Equivalent to 'filterMap', but the function accepts the key, -- as well as the value. -- - -- @since 1.0.?? + -- @since 1.0.19.0 filterWithKey :: (ContainerKey map -> MapValue map -> Bool) -> map -> map filterWithKey p = mapFromList . filter (uncurry p) . mapToList From fa9117fe37ea9674d3d1814b2f4efe1b75e38097 Mon Sep 17 00:00:00 2001 From: L0neGamer Date: Fri, 12 Jul 2024 20:40:01 +0100 Subject: [PATCH 4/4] add to changelog --- mono-traversable/ChangeLog.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/mono-traversable/ChangeLog.md b/mono-traversable/ChangeLog.md index 4f0b449d..c417a51c 100644 --- a/mono-traversable/ChangeLog.md +++ b/mono-traversable/ChangeLog.md @@ -1,5 +1,10 @@ # ChangeLog for mono-traversable +## 1.0.19.0 + +* Added `filterWithKey` to `IsMap`. + [#232](https://github.com/snoyberg/mono-traversable/pull/232) + ## 1.0.18.0 * Added MonoPointed instance for text Builder