Skip to content

Instantly share code, notes, and snippets.

@samdphillips
Last active January 7, 2019 18:18
Show Gist options
  • Save samdphillips/98488ff9acede0f37e5897c077009ae9 to your computer and use it in GitHub Desktop.
Save samdphillips/98488ff9acede0f37e5897c077009ae9 to your computer and use it in GitHub Desktop.
Racket map over a hash with for/hash
Welcome to Racket v7.0.
> (for/hash ([x 10]) (values x x))
'#hash((0 . 0)
       (1 . 1)
       (2 . 2)
       (3 . 3)
       (4 . 4)
       (5 . 5)
       (6 . 6)
       (7 . 7)
       (8 . 8)
       (9 . 9))
> (define h (for/hash ([x 10]) (values x x)))
> (for/hash ([(k v) (in-hash h)]) (values k (+ 10 v)))
'#hash((0 . 10)
       (1 . 11)
       (2 . 12)
       (3 . 13)
       (4 . 14)
       (5 . 15)
       (6 . 16)
       (7 . 17)
       (8 . 18)
       (9 . 19))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment