unzip ( assoc -- keys values ) (original) (raw)
unzip ( assoc -- keys values )
Factor handbook » The language » Collections » Associative mapping operations » Associative mapping conversions
Prev: | zip-with-as ( ... seq quot: ( ... key -- ... value ) exemplar -- ... assoc ) |
---|
Vocabulary
assocs
Inputs
assoc | an assoc |
---|
Outputs
keys | a sequence |
---|---|
values | a sequence |
Word description
Outputs an array of keys and an array of values of the input assoc.
Examples
USING: prettyprint assocs kernel ; { { 1 4 } { 2 5 } { 3 6 } } unzip [ . ] bi@
{ 1 2 3 } { 4 5 6 }
See also
zip, zip-as, zip-index, zip-index-as, zip-with, zip-with-as
Definition
GENERIC: unzip ( assoc -- keys values )
Methods
USING: assocs kernel sequences ;
M: assoc unzip
dup assoc-empty? [ drop { } { } ] [ >alist flip first2 ] if
;
USING: accessors arrays assocs kernel sequences ;
M: enumerated unzip
seq>> [ length ] keep [ >array ] bi@ ;
USING: accessors assocs hashtables hashtables.private kernel
sequences vectors ;
M: hashtable unzip
[ assoc-size dup [ ] bi@ ] [ array>> ] bi
[ [ suffix! ] bi-curry@ bi* ] each-pair [ { } like ] bi@ ;