Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add filterWithKey and bump classyprelude cabal version #232

Merged
merged 4 commits into from
Jul 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ cabal.sandbox.config
.stack-work/
tarballs/
*~
dist-newstyle/
5 changes: 5 additions & 0 deletions mono-traversable/ChangeLog.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion mono-traversable/mono-traversable.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -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 <https://www.stackage.org/package/mono-traversable>
category: Data
Expand Down
2 changes: 1 addition & 1 deletion mono-traversable/package.yaml
Original file line number Diff line number Diff line change
@@ -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 <https://www.stackage.org/package/mono-traversable>
category: Data
Expand Down
17 changes: 15 additions & 2 deletions mono-traversable/src/Data/Containers.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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.19.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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Loading