The magic function for the general case of key, f⌸
{ 0=⎕nc'⍺':⍵ ∇ ⍳≢⍵ ⍝ f⌸ x ←→ x f⌸ ⍳≢x ⍺ ⍺⍺{⍺ ⍺⍺ ⍵}{ ⎕ml←1 ⍝ needed by ↑⍵ and ⍺⊂⍵ j←⍋i⊣⎕dr i←⍳⍨⍺ ↑ (⊂[1↓⍳⍴⍴⍺]((⍳≢i)=⍳⍨i)⌿⍺) ⍺⍺¨ (2≠/¯1,i[j]) ⊂[⎕io] ⍵⌷⍨⊂j }⍵ }