2 ms·
Sorry. This page wasn't really written as an introduction; more a collection of ideas. To break that example down for you, the outer {} indicate that this is a
by RodgerTheGreat 7y ago
Sorry. This page wasn't really written as an introduction; more a collection of ideas.
To break that example down for you, the outer {} indicate that this is an anonymous function. It is implicitly a function over a single argument named "x"; our list of dictionaries. Expressions read right to left, so the first semantic unit is:
k:?,/!:'x
The variable "k" gets the distincts (?) of the concatenate-reduction (,/) of the keys (!:) of each (') dictionary:
!:'x
(,`a
,`b
`a `b)
,/!:'x
`a `b `a `b
?,/!:'x
`a `b
The other embedded lambda "{x@&~_n~/:x}" is read as "x indexed (@) by where (&) not (~) null (_n) matches (~) each-right (x)"; it filters nulls from a list.
_n~/:(22;;33;55)
0 1 0 0
~_n~/:(22;;33;55)
1 0 1 1
&~_n~/:(22;;33;55)
0 2 3
{x@&~_n~/:x}(22;;33;55)
22 33 55
Then the overall construction "{x@&~_n~/:x}x@'/:k" can be understood as "reach into each dictionary with all the keys and filter them to non-null values". Now you have a list of lists of values in the order that the keys appeared.
Finally, ".+(k; ... )" joins our keyset with the values we found for each key. Make dictionary (.) from the transpose (+) of the pair of vectors (k;v).
Does that help?