Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Mike, after impact, I will carve out time to build a keys() operator for hashes. </p> <p>In the meantime, what I have done to get around this is to keep a separate array of the keys. That way, I can use map, filter and all of the set operations on the <em>index</em> and then use the those values as my keys for the hash operations</p> <pre><code>key_array = ["key1","key2","key3"]; my_hash = { "key1" : "value1", "key2" : "value2", "key3" : "value3" }; </code></pre> <p>This really only works if you are controlling the values in the hash, but here is some example code:</p> <pre><code>global { kvHash = { "key1" : "value1", "key2" : "value2", "key3" : "value3" }; kArray = ["key1","key2","key3"]; } pre { pickKey = kArray[1]; value = kvHash.pick("$.#{pickKey}"); // add a new value newKey = "key4"; newVal = "value4"; newArray = kArray.union(newKey); newHash = kvHash.put([newKey],newVal); } </code></pre> <p>Noticed that I used the set operator <strong><a href="http://docs.kynetx.com/docs/Sets#Union_.28A_.E2.88.AA_B.29" rel="nofollow">union</a></strong> to keep the array full of unique values</p> <p>The javascript that is generated shows what this does:</p> <pre><code>var pickKey = 'key2'; var value = 'value2'; var newKey = 'key4'; var newVal = 'value4'; var newArray = ['key1', 'key2', 'key3', 'key4']; var newHash = {'key2' :'value2','key1' :'value1','key4' :'value4','key3' :'value3'}; </code></pre> <p>Now, you can use the <strong><a href="http://docs.kynetx.com/docs/Map" rel="nofollow">map</a></strong> or <strong><a href="http://docs.kynetx.com/docs/Filter" rel="nofollow">filter</a></strong> operators to pass each value individually to a function</p> <pre><code>c.map(function(x){x+2}) c.filter(function(x){x&lt;5}) </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload