racket-collections
racket-collections copied to clipboard
Adding update-ref functions?
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 :)
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
.