[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:947](https://github.com/evoluhq/evolu/blob/037c390af081e9944d616ff298a729515c5c5ab7/packages/common/src/Result.ts#L947)

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<
  Result<Profile, UserNotFoundError | ProfileNotFoundError>,
  typeof profile
>();
assertOk(profile, { userId: "user-1" });
```