# `each`, `peach`

_Iterate a unary_
```syntax
 v1 each x   each[v1;x]       v1 peach x   peach[v1;x]  
(vv)each x   each[vv;x]      (vv)peach x   peach[vv;x]
```

Where

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

applies `v1` or `vv` as a unary to each item of `x` and returns a result of the same length.

That is, the projections `each[v1;]`, `each[vv;]`, `peach[v1;]`, and `peach[vv;]` are [uniform](../basics/glossary.md#uniform-function) functions.
```q
q)count each ("the";"quick";" brown";"fox")
3 5 6 3
q)(+\)peach(2 3 4;(5 6;7 8);9 10 11 12)
2 5 9
(5 6;12 14)
9 19 30 42
```

`each` and `peach` perform the same computation and return the same result.

`peach` will divide the work between available secondary tasks. See [Parallel processing](../basics/peach.md) for details.

`each` is a wrapper for the [Each iterator](maps.md#each).
`peach` is a wrapper for the [Each Parallel iterator](maps.md#each-parallel).
It is good q style to use `each` and `peach` for unary values.

> **Warning — `each` is redundant with [atomic functions](../basics/atomic.md).**
>
>
[Maps](maps.md) for uses of Each with binary and higher-rank values


[`.Q.fc` parallel on cut](dotq.md#fc-parallel-on-cut)


Parallel processing


[Table counts in a partitioned database](../kb/partition.md#table-counts)


_Q for Mortals_
[A.49 `peach`](/q4m3/A_Built-in_Functions/#a68-peach)

## Higher-rank values

`peach` applies only unary values.
For a values of rank ≥2, use [Apply](apply.md) to project `v` as a unary value.

For example, suppose `m` is a 4-column matrix and each row has values for the arguments of `v4`. Then `.[v4;]peach m` will apply `v4` to each list of arguments.

Alternatively, suppose `t` is a table in which columns `b`, `c`, and `a` are arguments of `v3`. Then ``.[v3;]peach flip t `b`c`a`` will apply `v3` to the arguments in each row of `t`.

## Blocked within `peach`
```txt
hopen socket
websocket open
socket broadcast (25!x)
amending global variables
load master decryption key (-36!)
```

And any **system command** which might cause a change of global state.

Generally, do not use a **socket** within `peach`, unless it is encapsulated via [one-shot sync request](hopen.md#one-shot-request) or HTTP client request (TLS/SSL support added in 4.1t 2023.11.10). Erroneous socket usage is blocked and signals a `nosocket` error.

If you are careful to manage your **file handles/file access** so that there is no parallel use of the same handle (or file) across threads, then you can open and close files within `peach`.

**Streaming execute** ([`-11!`](../basics/internal.md#-11-streaming-execute)) should also be fine. However updates to global variables are not possible, so use cases might be quite restricted within `peach`.
