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

# Function: inspect()

Executes a side effect function on the value of a [Some](/api/types/Option.Some.md) in an [Option](/api/types/Option.Option.md) or [OptionAsync](/api/types/Option.OptionAsync.md),
without modifying the original option. This is useful for debugging, logging, or performing
other side effects while maintaining the original value.

If the input is a [None](/api/types/Option.None.md), the provided function is never called and the option is returned unchanged.

## Type Param

**O**

The input [Option](/api/types/Option.Option.md) or [OptionAsync](/api/types/Option.OptionAsync.md).

## Type Param

**R**

The return type of the inspection function.

## Examples

**Some Case**

```ts
import { Option } from 'byenull';

const option = Option.pipe(
  Option.some(42),
  Option.inspect((value) => console.log('Debug:', value)),
);
// Console output: "Debug: 42"
// Option: { type: 'Some', value: 42 }
```

**None Case (fn is never called)**

```ts
import { Option } from 'byenull';

const option = Option.pipe(
  Option.none(),
  Option.inspect((value: number) => console.log('Debug:', value)),
);
// No console output
// Option: { type: 'None' }
```

**Asynchronous Side Effect**

```ts
import { Option } from 'byenull';

const option = await Option.pipe(
  Option.some(42),
  Option.inspect(async (value) => {
    await fetch(`/api/logs?value=${value}`);
  }),
);
// { type: 'Some', value: 42 }
```

## See

- [inspectNone](/api/functions/Option.inspectNone.md) - For inspecting a [None](/api/types/Option.None.md) instead.
- [pipe](/api/functions/Option.pipe.md) - It is recommended to use this function with the [pipe](/api/functions/Option.pipe.md) function for better readability and composability.

## Call Signature

> **inspect**\<`O`, `R`>(`fn`): (`option`) => [`OptionFor`](/api/types/Option.OptionFor.md)\<`O` | `R`, [`InferSome`](/api/types/Option.InferSome.md)\<`O`>>

### Type Parameters

#### O

`O` _extends_ [`OptionMaybeAsync`](/api/types/Option.OptionMaybeAsync.md)\<`any`>

#### R

`R` _extends_ `void` | `Promise`\<`void`>

### Parameters

#### fn

(`a`) => `R`

### Returns

(`option`) => [`OptionFor`](/api/types/Option.OptionFor.md)\<`O` | `R`, [`InferSome`](/api/types/Option.InferSome.md)\<`O`>>

## Call Signature

> **inspect**\<`F`>(`fn`): \<`O`>(`option`) => [`OptionFor`](/api/types/Option.OptionFor.md)\<`O` | `ReturnType`\<`F`>, [`InferSome`](/api/types/Option.InferSome.md)\<`O`>>

### Type Parameters

#### F

`F` _extends_ (`a`) => `void` | `Promise`\<`void`>

### Parameters

#### fn

`F`

### Returns

\<`O`>(`option`) => [`OptionFor`](/api/types/Option.OptionFor.md)\<`O` | `ReturnType`\<`F`>, [`InferSome`](/api/types/Option.InferSome.md)\<`O`>>
