Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

Feature request: `traverseKeys` and `traverseKeysWith`

Open
#771 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Stale
Tech stack
haskell
Domain
data

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

feature-request IntMap Map

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

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from haskell/containers

All issues in haskell/containers

Similar issues

More Haskell issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.