Skip to content

Compose out eaches

Learn to spot expressions with sequential Eaches such as this one:

first each reverse each v        / first of each reverse of each v

and replace them with function compositions like this:

'[first;reverse] each v          / last of each v

Combine Compose with over to join longer sequences of functions:

('[;] over (upper;first;reverse)) each v

In general, seek to replace patterns like

f each g each … h each v

with any of (the forms are equivalent)

('[;] over (f;g;…;h)) each v
(('[;]/) (f;g;…;h)) each v
'[;]/[(f;g;…;h)] each v

Here’s another example:

q)reverse each ,':[1 2 3 4]
1 2
2 3
3 4
q)'[reverse;,]':[1 2 3 4]
1 2
2 3
3 4

Compositions are faster than sequential Eaches (one iteration replaces many), and easier to read – and code!

0<('[type;key]) each paths         / dictionaries in lists of paths
Back to top