Feature request: `traverseKeys` and `traverseKeysWith`
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 35/100
Research direction
Start by reading the existing mapKeys, traverse, assocs, fromList, and fromListWith entry points in the containers implementation. Compare the proposed traverseKeys and traverseKeysWith behavior with those APIs, then verify duplicate-key handling and complexity before adding tests that establish the requested types and results.
Written by the indexing model from the issue text.
Description
Currently there are functions
mapKeys :: (Ord k) => (j -> k) -> Map j a -> Map k a
traverse :: (Applicative f) => (a -> f b) -> Map k a -> f (Map k b)
but nothing of the type (Applicative f, Ord k) => (j -> f k) -> Map j a -> f (Map k a).
A sample implementation:
traverseKeys :: (Applicative f, Ord k) => (j -> f k) -> Map j a -> f (Map k a)
traverseKeys f = fmap fromList . traverse (\(j, a) -> (,a) <$> f j) . assocs
traverseKeysWith :: (Applicative f, Ord k) => (a -> a -> a) -> (j -> f k) -> Map j a -> f (Map k a)
traverseKeysWith c f = fmap (fromListWith c) . traverse (\(j, a) -> (,a) <$> f j) . assocs
which is O(n log n), if I'm not mistaken; though I haven't looked through the internals of the implementation to dig for further optimizations.
- Dominant language
- Haskell
- Stars
- 355
- Forks
- 194
- Avg merge
- 2d 12h
- Merged PRs (30d)
- 6
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from haskell/containers
-
major-release strictness Tree
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
haskell/containers#1260 ·
-
Difficulty 5/5 Over a week Newbie friendliness 35/100
haskell/containers#1261 · 9 comments ·
-
IntSet low-hanging-fruit performance
Difficulty 3/5 1-2 days Newbie friendliness 58/100
haskell/containers#1251 ·
-
maintainability major-release
Difficulty 3/5 1-2 days Newbie friendliness 70/100
haskell/containers#1250 ·
-
Difficulty 4/5 3-5 days Newbie friendliness 50/100
haskell/containers#1242 ·
All issues in haskell/containers
Similar issues
-
language/en needs-triage
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
kubernetes/website#57846 · 2 comments ·
Maintainers usually reply within 2 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
attention: pr-welcome documentation
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
haskell/cabal#12402 · 1 reaction ·
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
objectionary/phino#1600 ·
Maintainers usually reply within 1 day