[racket] Apply proc with hasheq

From: Danny Yoo (dyoo at hashcollision.org)
Date: Tue Dec 18 02:11:50 EST 2012

The function I provided for hash->keyword-apply is unfortunately
broken; I forgot that there's a requirement on the order of the
keywords we pass to it.  Here's a revised version:


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(define (hash->keyword-apply f a-hash [rest-args '()])
  (define-values (keys vals)
    (for/fold ([keys '()] [vals '()])
              ([k (sort (hash-keys a-hash) string>? #:key symbol->string)])
      (values (cons (string->keyword (symbol->string k)) keys)
              (cons (hash-ref a-hash k) vals))))
  (keyword-apply f keys vals rest-args))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

Posted on the users mailing list.