racket-collections icon indicating copy to clipboard operation
racket-collections copied to clipboard

Adding update-ref functions?

Open dys-bigwig opened this issue 5 years ago • 1 comments

Hi there. I noticed updating functions (hash-update...) aren't included in the generic interface for indexables. Seems like it's an easy addition (though I could be wrong) by just adding them to collections-lib/data/collection/indexable.rkt like so:

(provide
 gen:indexable indexable? indexable/c
 ref set-ref update-ref)

(define-generics indexable
  (ref indexable . _)
  (set-ref indexable . _)
  (update-ref indexable . _)
  #:defaults
  ([hash? (define ref hash-ref)
          (define set-ref hash-set)
          (define update-ref hash-update)]
   [dict? (define ref dict-ref)
          (define set-ref dict-set)
          (define update-ref dict-update)]
   [sequence? (define ref nth)
              (define set-ref set-nth)
              (define update-ref update-nth)]))

Seems to work locally with just this change, but I'm not sure if there are some potential issues with their inclusion that I'm missing and so I didn't want to make a PR directly. Thanks :)

dys-bigwig avatar Jul 10 '19 01:07 dys-bigwig

I don’t see any reason why that couldn’t be added. I’d accept a PR. It should likely have a fallback procedure defined in terms of ref and set-ref.

lexi-lambda avatar Jul 10 '19 02:07 lexi-lambda