How to map over values of a hash table (racket)

hashtable, racket, scheme

Solution

Many years after this question was asked, Racket 8.6 added `hash-map/copy` to do this. It passes both keys and values of an existing hash table to a map function that returns two values - a new key and value to use in a newly returned table.

> (hash-map/copy (hash "apple" 1 "pear" 2) (lambda (k v) (values k (+ v 1))))
'#hash(("apple" . 2) ("pear" . 3))

Problem

I want to map a function over the values in a hash table, like so: ``` (hash-map add1 (hash "apple" 1 "pear" 2)) => #hash(("apple" . 2) ("pear" . 3)) ``` Is there a library function to do this? It'd be good to have one that worked on immutable hashetables too. I looked on PlaneT, but didn't see anything there. Now, if this really doesn't exist, I'll go ahead and write it. What would the etiquette for getting this into racket? I just fork it on github and add it to the standard library (and the docs!) and submit a pull request? Or should I make it a planeT first, and then ask for it to be moved in? I'd like to help, but I just don't know what's the 'proper' way to go about it.

Original source