> For AI agents: the complete documentation index is available at /byethrow/ja/llms.txt, the full documentation bundle is available at /byethrow/ja/llms-full.txt.

# Function: let()

Computes a **plain value** from the current success object and attaches it
to the existing object under the specified key.

- If the original result is a [Failure](/byethrow/ja/api/types/Result.Failure.md), it is returned as-is.
- If the original result is a [Success](/byethrow/ja/api/types/Result.Success.md), a new object is returned by shallow-merging:
  the original success object and `{ [name]: fn(value) }`.

This is the companion of [bind](/byethrow/ja/api/functions/Result.bind.md) for derivations that cannot fail.
`fn` is expected to be a pure, synchronous computation.
Use [bind](/byethrow/ja/api/functions/Result.bind.md) instead when the value comes from a fallible or asynchronous computation.


- `Success({ a })`: `fn({ a })` が `b` を返す → `Success({ a, b })`
- `Failure(e)`: `fn` は呼ばれない → `Failure(e)`


## Type Param

**N**

The key to assign the result of the `fn` computation.

## Type Param

**R1**

The input [Result](/byethrow/ja/api/types/Result.Result.md) or [ResultAsync](/byethrow/ja/api/types/Result.ResultAsync.md).

## Type Param

**T2**

The value type returned by `fn`.

## Examples

**Success Case**

```ts
import { Result } from '@praha/byethrow';

const result = Result.pipe(
  Result.succeed({ firstName: 'Alice', lastName: 'Smith' }),
  Result.let('fullName', ({ firstName, lastName }) => `${firstName} ${lastName}`),
);
// { type: 'Success', value: { firstName: 'Alice', lastName: 'Smith', fullName: 'Alice Smith' } }
```

**Failure Case**

```ts
import { Result } from '@praha/byethrow';

const result = Result.pipe(
  Result.fail('error'),
  Result.let('fullName', ({ firstName, lastName }) => `${firstName} ${lastName}`),
);
// { type: 'Failure', error: 'error' }
```

**Combined with bind**

```ts
import { Result } from '@praha/byethrow';

const result = Result.pipe(
  Result.do(),
  Result.bind('x', () => Result.succeed(1)),
  Result.bind('y', () => Result.succeed(2)),
  Result.let('z', ({ x, y }) => x + y),
);
// { type: 'Success', value: { x: 1, y: 2, z: 3 } }
```

## See

- [pipe](/byethrow/ja/api/functions/Result.pipe.md) - It is recommended to use this function with the [pipe](/byethrow/ja/api/functions/Result.pipe.md) function for better readability and composability.
- [bind](/byethrow/ja/api/functions/Result.bind.md) - Use this function instead when the value is computed by a [Result](/byethrow/ja/api/types/Result.Result.md)-producing function.

## Call Signature

> **let**\<`N`, `R1`, `T2`>(`name`, `fn`): (`result`) => [`InferSuccess`](/byethrow/ja/api/types/Result.InferSuccess.md)\<`R1`> _extends_ `object` ? [`ResultFor`](/byethrow/ja/api/types/Result.ResultFor.md)\<`R1`, \{ \[K in string | number | symbol]: K extends Exclude\<keyof InferSuccess, N> ? InferSuccess\[K] : T2 }, [`InferFailure`](/byethrow/ja/api/types/Result.InferFailure.md)\<`R1`>> : `unknown`

### Type Parameters

#### N

`N` _extends_ `string`

#### R1

`R1` _extends_ [`ResultMaybeAsync`](/byethrow/ja/api/types/Result.ResultMaybeAsync.md)\<`any`, `any`>

#### T2

`T2`

### Parameters

#### name

`N`

#### fn

(`a`) => `T2`

### Returns

(`result`) => [`InferSuccess`](/byethrow/ja/api/types/Result.InferSuccess.md)\<`R1`> _extends_ `object` ? [`ResultFor`](/byethrow/ja/api/types/Result.ResultFor.md)\<`R1`, \{ \[K in string | number | symbol]: K extends Exclude\<keyof InferSuccess, N> ? InferSuccess\[K] : T2 }, [`InferFailure`](/byethrow/ja/api/types/Result.InferFailure.md)\<`R1`>> : `unknown`

## Call Signature

> **let**\<`N`, `T1`, `T2`>(`name`, `fn`): \<`R1`>(`result`) => `T1` _extends_ `object` ? [`ResultFor`](/byethrow/ja/api/types/Result.ResultFor.md)\<`R1`, \{ \[K in string | number | symbol]: K extends Exclude\<keyof T1, N> ? T1\[K] : T2 }, [`InferFailure`](/byethrow/ja/api/types/Result.InferFailure.md)\<`R1`>> : `unknown`

### Type Parameters

#### N

`N` _extends_ `string`

#### T1

`T1`

#### T2

`T2`

### Parameters

#### name

`N`

#### fn

(`a`) => `T2`

### Returns

\<`R1`>(`result`) => `T1` _extends_ `object` ? [`ResultFor`](/byethrow/ja/api/types/Result.ResultFor.md)\<`R1`, \{ \[K in string | number | symbol]: K extends Exclude\<keyof T1, N> ? T1\[K] : T2 }, [`InferFailure`](/byethrow/ja/api/types/Result.InferFailure.md)\<`R1`>> : `unknown`
