# flatMap

Replaces a successful or outer optimistic value with another AsyncData value.

## Signatures

```ts
export declare const flatMap: {
    <A, B, E2>(f: (a: A, data: Success<A> | Optimistic<A, unknown>) => AsyncData<B, E2>): <E>(data: AsyncData<A, E>) => AsyncData<B, E | E2>;
    <A, E, B, E2>(data: AsyncData<A, E>, f: (a: A, data: Success<A> | Optimistic<A, E>) => AsyncData<B, E2>): AsyncData<B, E | E2>;
};
```

## Why

State-producing transformations can change both value and error types while non-value states pass through unchanged.

## Ownership and lifetime

This pure transformation acquires no resources; ownership follows the AsyncData returned by the callback.

## Examples

```ts
import { flatMap, success } from "@typed/async-data"
const parsed = flatMap(success("2"), (text) => success(Number(text)))
```
