# Subscription.overload

Groups several definitions of one subscription kind into a single function whose items depend
on its params. A call goes to the first variant whose params accept the arguments.

## Usage

```ts
import { Schema } from "effect";
import { Hash } from "@ethect/core";
import { Subscription, Transaction } from "@ethect/core/rpc";

const full = Schema.Literal(true);
const hashes = Schema.optionalKey(Schema.Literal(false));

const pending = Subscription.overload(
  Subscription.make<[full: unknown]>()("newPendingTransactions", [full], Transaction.schema),
  Subscription.make<[full?: unknown]>()("newPendingTransactions", [hashes], Hash.schema),
);

pending(); // Stream<Hash, …>: the hash of each pending transaction
pending(true); // Stream<Transaction, …>: each pending transaction in full
```

This is how [`Eth.subscribe.newPendingTransactions`](https://ethect.dev/rpc/eth/subscribe/new-pending-transactions/)
is defined.

## Returns

A function with the call signatures of every variant, plus two properties:

| Property | Type | Holds |
| --- | --- | --- |
| `kind` | `string` | the kind of the first variant |
| `variants` | a tuple of [`Subscription`](https://ethect.dev/rpc/subscription/) | the definitions, in order |

## Parameters

### variants

- **Type:** one or more [`Subscription`](https://ethect.dev/rpc/subscription/), as separate arguments

The definitions to group. They normally share a kind and differ by a literal in their params.

```ts
import { Schema } from "effect";
import { Hash } from "@ethect/core";
import { Block, Subscription } from "@ethect/core/rpc";

const full = Schema.Literal("full");

const heads = Subscription.overload(
  Subscription.make<[detail: unknown]>()("acme_heads", [full], Block.headerSchema),
  Subscription.make()("acme_heads", [], Hash.schema),
);
```

## Behavior

- **First match wins.** The arguments are tested against each variant's params in order: put
  the most specific variant first.
- **No match falls back to the first variant**, whose stream then fails with a
  [`CodecError`](https://ethect.dev/reference/errors/codec-error/) on the params.
- **No `params` or `item` of its own.** Read them on a variant:
  `Eth.subscribe.newPendingTransactions.variants[0].item`.
