resyntax icon indicating copy to clipboard operation
resyntax copied to clipboard

Replace `hash-for-each` with `for`

Open jackfirth opened this issue 1 year ago • 0 comments

#lang resyntax/test

test: "hash-for-each should be refactored to for"
--------------------
#lang racket
(define (f h)
  (hash-for-each h (lambda (key val) (printf "key = ~a, val = ~a\n" key val))))
--------------------
--------------------
#lang racket
(define (f h)
  (for ([(key val) (in-hash h)])
    (printf "key = ~a, val = ~a\n" key val)))
--------------------

Should be similar to the for-each and map to for/list rules, where it's only refactored if the function given to hash-for-each is sufficiently complex.

jackfirth avatar Nov 05 '24 00:11 jackfirth