Associative array/Iteration: Difference between revisions

→‎{{header|Factor}}: show iterating over only keys or values
(Add Crystal implementation)
(→‎{{header|Factor}}: show iterating over only keys or values)
Line 1,057:
=={{header|Factor}}==
<lang factor>H{ { "hi" "there" } { "a" "b" } } [ ": " glue print ] assoc-each</lang>
<code>assoc-each</code> places both the key and the value on top of the data stack. A simple <code>drop</code> or <code>nip</code> enables iterating over only keys or values.
<lang factor>H{ { "hi" "there" } { "a" "b" } } [ drop print ] assoc-each ! print keys
H{ { "hi" "there" } { "a" "b" } } [ nip print ] assoc-each ! print values</lang>
There's also <code>assoc-map</code>, <code>assoc-find</code>, <code>assoc-filter</code> and many more.
 
1,820

edits