# Abi.tuple

Several values as one, by position. A value is a readonly tuple.

## Usage

```ts
import { Effect } from "effect";
import { Abi } from "@ethect/core";

// (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast)
const Reserves = Abi.tuple([Abi.uint112, Abi.uint112, Abi.uint32]);

const program = Effect.gen(function* () {
  const data = yield* Abi.encode(Reserves, [10n ** 18n, 3000n * 10n ** 6n, 1_700_000_000]);
  const [reserve0, reserve1, updatedAt] = yield* Abi.decode(Reserves, data);
  return { reserve0, reserve1, updatedAt }; // two bigints and a number
});
```

Use [`Abi.struct`](https://ethect.dev/reference/abi/struct/) when the components have names. The two encode to
the same bytes.

## Returns

[`Abi.Reference<readonly [A, B, …]>`](https://ethect.dev/reference/abi/#reference-types)

The tuple type. A value has one element per component, each of its component's type. It is an
`Abi.Type` that says it is a reference type.

## Parameters

### items

- **Type:** `ReadonlyArray<Abi.Type<any>>`

The types of the components, in order. At least one.

```ts
import { Abi } from "@ethect/core";

const Leg = Abi.tuple([Abi.address, Abi.uint24]);
// a tuple in a tuple, and an array of tuples
const Route = Abi.tuple([Abi.array(Leg), Abi.bytes]);
```

## Behavior

- **One value per component.** A value with fewer or more elements fails to encode, and the
  types refuse it.
- **A tuple of static types is static.** It is written in place, one word after the other.
  With one dynamic component it is written by offset, as the specification says.
- **A tuple has a component.** `Abi.tuple([])` does not throw: it gives a type whose every use
  fails with an `AbiError`.

## Errors

| Error | When |
| --- | --- |
| [`AbiError`](https://ethect.dev/reference/errors/abi-error/) | encoding a value that is not an array, or has another number of elements |
| `AbiError` | encoding an element its type refuses. The message says which: `at [1]` |
