> 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: andThrough()

Runs an additional computation using the success value of a [Result](/byethrow/ja/api/types/Result.Result.md) or [ResultAsync](/byethrow/ja/api/types/Result.ResultAsync.md),
but **returns the original result** if the additional computation is successful.

If either the original result or the side effect result is a [Failure](/byethrow/ja/api/types/Result.Failure.md), that failure is returned.
Useful for running validations or side effects without altering the main result on success.

## Type Param

**R1**

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

## Type Param

**R2**

The result type returned by `fn`.

## Examples

**Success Case**

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

const result = Result.pipe(
  Result.succeed(5),
  Result.andThrough((x) => {
    return x > 0 ? Result.succeed(null) : Result.fail('Must be > 0');
  }),
);
// { type: 'Success', value: 5 }
```

**Failure Case (input is a Failure)**

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

const result = Result.pipe(
  Result.fail('error'),
  Result.andThrough((x) => {
    return x > 0 ? Result.succeed(null) : Result.fail('Must be > 0');
  }),
);
// { type: 'Failure', error: 'error' }
```

**Failure Case (function returns a Failure)**

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

const result = Result.pipe(
  Result.succeed(-10),
  Result.andThrough((x) => {
    return x > 0 ? Result.succeed(null) : Result.fail('Must be > 0');
  }),
);
// { type: 'Failure', error: 'Must be > 0' }
```

## 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.

## Call Signature

> **andThrough**\<`R1`, `R2`>(`fn`): (`result`) => [`ResultFor`](/byethrow/ja/api/types/Result.ResultFor.md)\<`R1` | `R2`, [`InferSuccess`](/byethrow/ja/api/types/Result.InferSuccess.md)\<`R1`>, [`InferFailure`](/byethrow/ja/api/types/Result.InferFailure.md)\<`R1`> | [`InferFailure`](/byethrow/ja/api/types/Result.InferFailure.md)\<`R2`>>

### Type Parameters

#### R1

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

#### R2

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

### Parameters

#### fn

(`a`) => `R2`

### Returns

(`result`) => [`ResultFor`](/byethrow/ja/api/types/Result.ResultFor.md)\<`R1` | `R2`, [`InferSuccess`](/byethrow/ja/api/types/Result.InferSuccess.md)\<`R1`>, [`InferFailure`](/byethrow/ja/api/types/Result.InferFailure.md)\<`R1`> | [`InferFailure`](/byethrow/ja/api/types/Result.InferFailure.md)\<`R2`>>

## Call Signature

> **andThrough**\<`F`>(`fn`): \<`R1`>(`result`) => [`ResultFor`](/byethrow/ja/api/types/Result.ResultFor.md)\<`R1` | `ReturnType`\<`F`>, [`InferSuccess`](/byethrow/ja/api/types/Result.InferSuccess.md)\<`R1`>, [`InferFailure`](/byethrow/ja/api/types/Result.InferFailure.md)\<`R1`> | [`InferFailure`](/byethrow/ja/api/types/Result.InferFailure.md)\<`F`>>

### Type Parameters

#### F

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

### Parameters

#### fn

`F`

### Returns

\<`R1`>(`result`) => [`ResultFor`](/byethrow/ja/api/types/Result.ResultFor.md)\<`R1` | `ReturnType`\<`F`>, [`InferSuccess`](/byethrow/ja/api/types/Result.InferSuccess.md)\<`R1`>, [`InferFailure`](/byethrow/ja/api/types/Result.InferFailure.md)\<`R1`> | [`InferFailure`](/byethrow/ja/api/types/Result.InferFailure.md)\<`F`>>
