Skip to main content

⌸ — Key

Monadic operator. Keys: Alt-q =. Hanzi: 组 (組)

K f⌸Y groups major cells of Y by the corresponding major cells of K, the keys. Calls key f group; groups appear in first-occurrence order.

1 1 2{+/ω}⌸10 20 30 ⍝ 30 30

f⌸Y is Y f⌸ι≢Y: the major cells of Y are the keys, and their positions are the values.

Keys match with tolerance, as in ≠. Results are assembled with fill. With empty input, f is called once on prototypes, to give the result’s cell shape.

Fast combinations

BPL computes each of these combinations with a dedicated algorithm. Trains says which spellings BPL recognises.

Combination Applies to Benefit
≢ᵘ⌸Y or K ≢ᵘ⌸Y any keys counts each group’s major cells without building the groups
K f/ᵘ⌸Y or K f⌿ᵘ⌸Y, with f of + ⌈ ⌊, or × of floats a vector Y of floats, integers or Booleans folds every group in one pass, without a call of the operand for each group

Unary ᵘ makes the operand ignore the key and use the group as its right argument.

≢ᵘ⌸"banana"                                ⍝ [1 3 2]ₓ
1 1 2 +/ᵘ⌸ 10 20 30                        ⍝ 30 30
(•explain "1 1 2 +/ᵘ⌸ 10 20 30").fast.rule  ⍝ ["group folds"]