"Mapping between assocs and sequences:"
{ $subsections
map>assoc
+ map>alist
assoc>map
assoc-map-as
}
{ $values { "seq" sequence } { "quot" { $quotation ( ... elt -- ... key value ) } } { "exemplar" assoc } { "assoc" "a new assoc" } }
{ $description "Applies the quotation to each element of the sequence, and collects the keys and values into a new assoc having the same type as " { $snippet "exemplar" } "." } ;
+HELP: map>alist
+{ $values { "seq" sequence } { "quot" { $quotation ( ... elt -- ... key value ) } } { "assoc" "a new assoc" } }
+{ $description "Applies the quotation to each element of the sequence, and collects the keys and values into a new alist." } ;
+
+{ map>assoc map>alist } related-words
+
HELP: assoc>map
{ $values { "assoc" assoc } { "quot" { $quotation ( ... key value -- ... elt ) } } { "exemplar" sequence } { "seq" "a new sequence" } }
{ $description "Applies the quotation to each entry of the assoc and collects the results into a new sequence of the same type as the exemplar." } ;
[ [ swapd set-at ] curry compose each ] keep
] if ; inline
+: map>alist ( ... seq quot: ( ... elt -- ... key value ) exemplar -- ... alist )
+ { } map>assoc ; inline
+
: extract-keys ( seq assoc -- subassoc )
[ [ dupd at ] curry ] keep map>assoc ;