Adding dict-keys,values,->list
This commit is contained in:
parent
f23daa3aea
commit
a8fc09b49a
|
@ -29,6 +29,10 @@
|
|||
in-dict-keys
|
||||
in-dict-values
|
||||
in-dict-pairs
|
||||
|
||||
dict-keys
|
||||
dict-values
|
||||
dict->list
|
||||
|
||||
(rename-out [create-custom-hash make-custom-hash]
|
||||
[create-immutable-custom-hash make-immutable-custom-hash])
|
||||
|
@ -459,6 +463,20 @@
|
|||
(for ([(k v) (in-dict d)])
|
||||
(f k v)))
|
||||
|
||||
(define (dict-keys d)
|
||||
(for/list ([k (in-dict-keys d)])
|
||||
k))
|
||||
|
||||
(define (dict-values d)
|
||||
(for/list ([v (in-dict-values d)])
|
||||
v))
|
||||
|
||||
(define (dict->list d)
|
||||
(for/list ([k*v (in-dict-pairs d)])
|
||||
k*v))
|
||||
|
||||
|
||||
|
||||
;; ----------------------------------------
|
||||
|
||||
(struct hash-box (key))
|
||||
|
|
|
@ -404,7 +404,35 @@ key and value as separate values for each element).
|
|||
p)
|
||||
]}
|
||||
|
||||
@defproc[(dict-keys [dict dict?]) list?]{
|
||||
Returns a list of the keys from
|
||||
@scheme[dict] in an unspecified order.
|
||||
|
||||
@examples[
|
||||
#:eval dict-eval
|
||||
(define h #hash((a . "apple") (b . "banana")))
|
||||
(dict-keys h)
|
||||
]}
|
||||
|
||||
@defproc[(dict-values [dict dict?]) list?]{
|
||||
Returns a list of the values from
|
||||
@scheme[dict] in an unspecified order.
|
||||
|
||||
@examples[
|
||||
#:eval dict-eval
|
||||
(define h #hash((a . "apple") (b . "banana")))
|
||||
(dict-values h)
|
||||
]}
|
||||
|
||||
@defproc[(dict->list [dict dict?]) list?]{
|
||||
Returns a list of the associations from
|
||||
@scheme[dict] in an unspecified order.
|
||||
|
||||
@examples[
|
||||
#:eval dict-eval
|
||||
(define h #hash((a . "apple") (b . "banana")))
|
||||
(dict->list h)
|
||||
]}
|
||||
|
||||
@defthing[prop:dict struct-type-property?]{
|
||||
|
||||
|
|
|
@ -23,6 +23,10 @@
|
|||
(test can-remove? dict-can-remove-keys? d)
|
||||
(test can-update? dict-can-functional-set? d)
|
||||
|
||||
(test (dict-map d cons) 'dict->list (dict->list d))
|
||||
(test (dict-map d (λ (k v) k)) 'dict-keys (dict-keys d))
|
||||
(test (dict-map d (λ (k v) v)) 'dict-values (dict-values d))
|
||||
|
||||
(test (dict-map d cons) 'in-dict
|
||||
(for/list ([(k v) (in-dict d)])
|
||||
(cons k v)))
|
||||
|
|
Loading…
Reference in New Issue
Block a user