q←⍎¨V←40⍴ '2+2' '+/⍳1E7'
Let's execute each unique element only once.
q≡{(⍎¨⍵)[⍵⍳⍺]}∘∪⍨ V
1
EEN←{(⍎¨⍵)[⍵⍳⍺]}∘∪⍨ ⍝ fn: execute each nub
q≡EEN V
1
Execute is one function: an operator would make the technique useful for others.
q≡⍎{(⍺⍺¨⍵)[⍵⍳⍺]}∘∪⍨ V
1
EN←{(⍺⍺¨⍵)[⍵⍳⍺]}∘∪⍨ ⍝ op: each-nub
SYNTAX ERROR
EN←{(⍺⍺¨⍵)[⍵⍳⍺]}∘∪⍨ ⍝ op: each-nub
∧
Oops. Compose will take a function as left-operand (⍎{(⍺⍺¨⍵)[⍵⍳⍺]}) but not an operator. A wrapper removes the difficulty.
EN←{⍺⍺{(⍺⍺¨⍵)[⍵⍳⍺]}∘∪⍨⍵} ⍝ op: each-nub
q≡⍎EN V
1
It seems a pity to use the wrapper. Can it be elided?
Stephen
PS Functionistas might prefer to lose the index brackets. Perhaps that looks better because the ⍺⍺s aren't juxtaposed.
EN←{⍺⍺{(⍵⍳⍺)⊃¨⊂⍺⍺¨⍵}∘∪⍨⍵} ⍝ op: each-nub
q≡⍎EN V
1
SJT