---
title: "zip: shader function examples, uses and input limits"
description: "Zip combines corresponding elements from two equal-length arrays. Use it for pairing samples with weights or computing pairwise products."
url: https://typeshade.dev/reference/functions/zip/
language: en
---

# `zip`

Function

Zip combines corresponding elements from two equal-length arrays.

## Compare examples

Each output element multiplies the two input elements at the same index. A zero in either input makes that product zero.

**Model assumptions**`xs = array(1, 2, 3)`

**Example 1`zip(xs, array(4, 5, 6), (a, b) => a * b)`**

`4` `10` `18`

Components in this example

**Result**

`[4,10,18]`

**Example 2`zip(xs, array(0, 0, 0), (a, b) => a * b)`**

`0` `0` `0`

Components in this example

**Result**

`[0,0,0]`

**Example 3`zip(xs, array(-1, -1, -1), (a, b) => a * b)`**

`-1` `-2` `-3`

Components in this example

**Result**

`[-1,-2,-3]`

The examples are calculation models and do not run GPU work. The reference below gives the complete call signatures. Decimal results are rounded for display. The stated assumptions determine each example; actual shader results follow the target precision and execution rules.

## When to use it

Use it for pairing samples with weights or computing pairwise products.

## Inputs and limits

Both arrays must have the same fixed length. The combining function decides the output element type.

For shader input rules and precision, consult [WGSL](https://www.w3.org/TR/WGSL/) and [GLSL ES 3.00](https://registry.khronos.org/OpenGL/specs/es/3.0/GLSL_ES_Specification_3.00.pdf).

## Related functions

- [`array`](https://typeshade.dev/reference/functions/array/)

The signature, the sentence and any message are the compiler's own text at commit af54ddad5.

A fixed-size array built from two of one length, element by element: `zip(xs, ys, (a, b) => a * b)`.

## Syntax

```ts
declare function zip<A, B, R, N extends number>(
  xs: array<A, N>,
  ys: array<B, N>,
  f: (a: A, b: B) => R,
): array<R, N>
```

A `number` in a parameter or a return position is the scalar slot. The ambient file declares a GPU scalar as a branded number whose brand is optional, so a literal and any branded scalar both fill it.

`type f32 = number & { readonly [f32Tag]?: true }`

A `number` you write as a type is inferred from its uses, and `f32`, `i32` and `u32` fix a width; [the TypeScript constructs page](https://typeshade.dev/guide/language/from-typescript/) carries that row with the compiler's emit.

## Parameters

- `xs` `array<A, N>`
- `ys` `array<B, N>`
- `f` `(a: A, b: B) => R`

## Return value

`array<R, N>`

## Description

Unrolled into one call per element; the function may read the variables around it.

## See also

- [Functions](https://typeshade.dev/reference/functions/)
