# `over`, `scan`

_Wrappers for the Over and Scan iterators_

The keywords `over` and `scan` are wrappers for the accumulating iterators, [Over and Scan](accumulators.md).
Prefer `over` and `scan` with unary and binary values.

Like Over and Scan, `over` and `scan` share the same syntax and perform the same computation. `scan` returns the result of each evaluation; `over` returns only the last.

## Converge
```syntax
 v1 over x    over[v1;x]        v1 scan x    scan[v1;x]
(vv)over x    over[vv;x]       (vv)scan x    scan[vv;x]
```

Where

- `v1` is a unary [applicable value](glossary.md#applicable-value)
- `vv` is a [variadic](variadic.md) applicable value

applies the value progressively to `x`, then to `v1[x]` (or `vv[x]`), and so on, until the result matches (within [comparison tolerance](precision.md#comparison-tolerance)) either

- the previous result, or
- `x`
```q
q)n:("the ";("quick ";"brown ";("fox ";"jumps ";"over ");"the ");("lazy ";"dog."))
q)raze over n
"the quick brown fox jumps over the lazy dog."
q)(,/)over n
"the quick brown fox jumps over the lazy dog."
q){x*x} scan .01
0.01 0.0001 1e-08 1e-16 1e-32 1e-64 1e-128 1e-256 0
```

For more detail, and for the related forms Do and While, see [Accumulators](accumulators.md).

## MapReduce, Fold
```syntax
v2 over x   over[v2;x]        v2 scan x   scan[v2;x]
```

Where `v2` is a binary [applicable value](glossary.md#applicable-value), applies `v2` progressively between successive items.

`scan[v2;]` is a [uniform function](glossary.md#uniform-function) and `over[v2;]` is an [aggregate function](glossary.md#aggregate-function).
```q
q)(+) scan 1 2 3 4 5
1 3 6 10 15
q)(*) over 1 2 3 4 5
120
```

## Keywords

Several q keywords are common projections of `scan` and `over`.
For example, `sums` is `scan[+;]` and `prd` is `over[*;]`.

For efficiency and good q style, prefer these keywords;
for example, use `prd` rather than `over[*;]` or `*/`.
```txt
keyword  equivalents
---------------------------------------
all      over[and;]   &/  Lesser Over
any      over[or;]    |/  Greater Over
max      over[|;]     |/  Greater Over
maxs     scan[|;]     |\  Greater Scan
min      over[&;]     &/  Lesser Over
mins     scan[&;]     &\  Lesser Scan
prd      over[*;]     */  Multiply Over
prds     scan[*;]     *\  Multiply Scan
raze     over[,;]     ,/  Join Over
sum      over[+;]     +/  Add Over
sums     scan[+;]     +\  Add Scan
```

----

[Accumulators](accumulators.md)
