[API reference](https://evolu.dev/docs/api-reference) › [@evolu/common](https://evolu.dev/docs/api-reference/common) › [Result](https://evolu.dev/docs/api-reference/common/Result) › flatMapResult

```ts
function flatMapResult<T, E, U, F>(
  result: Result<T, E>,
  fn: (value: T) => Result<U, F>,
): Result<U, E | F>;
```

Defined in: [packages/common/src/Result.ts:942](https://github.com/evoluhq/evolu/blob/dd96d79f1dbe9a49fa12ce8e0aa7d3d0177795ca/packages/common/src/Result.ts#L942)

Composes a successful [Result](https://evolu.dev/docs/api-reference/common/Result/type-aliases/Result) with another Result-returning operation.

Returns the existing error without calling the operation when the Result has
failed.

Do not nest `flatMapResult`. For longer workflows, use explicit checks, which
keep names, intermediate values, and control flow flat and easy to read.

### Example

```ts
import {
  assertOk,
  assertType,
  flatMapResult,
  ok,
  type Result,
  type Typed,
} from "@evolu/common";

interface User {
  readonly id: string;
}

interface UserNotFoundError extends Typed<"UserNotFound"> {}

interface Profile {
  readonly userId: string;
}

const getProfile = (userId: string): Result<Profile, ProfileNotFoundError> =>
  ok({ userId });

interface ProfileNotFoundError extends Typed<"ProfileNotFound"> {}

const user: Result<User, UserNotFoundError> = ok({ id: "user-1" });
const profile = flatMapResult(user, ({ id }) => getProfile(id));
assertType<
  typeof profile,
  Result<Profile, UserNotFoundError | ProfileNotFoundError>
>();
assertOk(profile, { userId: "user-1" });
```