# [`⌸`](https://bpl.fast.ai//glyphs/quad-equal.html) — 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.

```bpl
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](../evaluation.md#equality-and-ordering), as in [`≠`](https://bpl.fast.ai//glyphs/not-equals.html). Results are assembled with fill. With empty input, `f` is called once on [prototypes](../terms.md#term-prototype), to give the result's cell shape.

## Fast combinations

BPL computes each of these combinations with a dedicated algorithm. [Trains](../evaluation.md#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 [`×`](https://bpl.fast.ai//glyphs/times.html) 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](superscript-u.md) [`ᵘ`](https://bpl.fast.ai//glyphs/superscript-u.html) makes the operand ignore the key and use the group as its right argument.

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