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

# Namespace: Option

Re-exports core Option-handling utilities under two convenient namespaces:

- `Option`: Verbose and explicit usage
- `O`: Shorthand alias for more concise code

## Examples

**Basic Usage**

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

const findUser = Option.fn((id: string) =>
  id.startsWith('u') ? { id, name: 'John Doe' } : null,
);

const option = Option.pipe(
  Option.some('u123'),
  Option.andThen(findUser),
  Option.map((user) => user.name),
);

if (Option.isSome(option)) {
  console.log(option.value); // John Doe
}
```

**Shorthand Usage**

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

const findUser = O.fn((id: string) =>
  id.startsWith('u') ? { id, name: 'John Doe' } : null,
);

const option = O.pipe(
  O.some('u123'),
  O.andThen(findUser),
  O.map((user) => user.name),
);

if (O.isSome(option)) {
  console.log(option.value); // John Doe
}
```

## Core Types

| Type Alias                                                | Description                                                                                                  |
| --------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------ |
| [None](/api/types/Option.None.md)                         | The variant of an [Option](/api/types/Option.Option.md) that holds no value.                                 |
| [NonNullableValue](/api/types/Option.NonNullableValue.md) | A value that is neither `null` nor `undefined`.                                                              |
| [Option](/api/types/Option.Option.md)                     | A union type representing either a [Some](/api/types/Option.Some.md) or a [None](/api/types/Option.None.md). |
| [OptionAsync](/api/types/Option.OptionAsync.md)           | An asynchronous variant of [Option](/api/types/Option.Option.md), wrapped in a `Promise`.                    |
| [OptionMaybeAsync](/api/types/Option.OptionMaybeAsync.md) | An option that may be either synchronous or asynchronous.                                                    |
| [Some](/api/types/Option.Some.md)                         | The variant of an [Option](/api/types/Option.Option.md) that holds a value.                                  |

## Infer Types

| Type Alias                                  | Description                                                                                                   |
| ------------------------------------------- | ------------------------------------------------------------------------------------------------------------- |
| [InferSome](/api/types/Option.InferSome.md) | Infers the [Some](/api/types/Option.Some.md) value type `T` from an Option or a function returning an Option. |
| [OptionFor](/api/types/Option.OptionFor.md) | Resolves to the appropriate Option type (sync or async) based on the input type.                              |

## Creators

| Function                                | Description                                                                                                                                           |
| --------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- |
| [fn](/api/functions/Option.fn.md)       | Wraps a function and returns a new function that returns an [Option](/api/types/Option.Option.md) or [OptionAsync](/api/types/Option.OptionAsync.md). |
| [maybe](/api/functions/Option.maybe.md) | Executes a function and wraps its result in an [Option](/api/types/Option.Option.md) or [OptionAsync](/api/types/Option.OptionAsync.md).              |
| [none](/api/functions/Option.none.md)   | Creates a [None](/api/types/Option.None.md): an `Option` that holds no value.                                                                         |
| [some](/api/functions/Option.some.md)   | Creates a [Some](/api/types/Option.Some.md) from a given value. Passing `null` or `undefined` returns [None](/api/types/Option.None.md) instead.      |

## Combinators

| Function                                            | Description                                                                                                                                                                                                                                                                                                                              |
| --------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [andThen](/api/functions/Option.andThen.md)         | Chains the next computation using the value of an [Option](/api/types/Option.Option.md) or [OptionAsync](/api/types/Option.OptionAsync.md). If the input is a [None](/api/types/Option.None.md), it is returned unchanged. Otherwise, the provided function is called, and its result is returned as-is.                                 |
| [inspect](/api/functions/Option.inspect.md)         | 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. |
| [inspectNone](/api/functions/Option.inspectNone.md) | Executes a side effect function when an [Option](/api/types/Option.Option.md) or [OptionAsync](/api/types/Option.OptionAsync.md) is a [None](/api/types/Option.None.md), without modifying the original option. This is useful for debugging, logging, or performing other side effects while maintaining the original value.            |
| [map](/api/functions/Option.map.md)                 | Applies a transformation function to the value of an [Option](/api/types/Option.Option.md) or [OptionAsync](/api/types/Option.OptionAsync.md). If the input is a [None](/api/types/Option.None.md), it is returned unchanged.                                                                                                            |
| [orElse](/api/functions/Option.orElse.md)           | Chains a fallback computation for an [Option](/api/types/Option.Option.md) or [OptionAsync](/api/types/Option.OptionAsync.md). If the input is a [Some](/api/types/Option.Some.md), it is returned unchanged. Otherwise, the provided function is called, and its result is returned as-is.                                              |

## Unwraps

| Function                                  | Description                                                                                                                                                                                              |
| ----------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [unwrap](/api/functions/Option.unwrap.md) | Extracts the value from an [Option](/api/types/Option.Option.md) or [OptionAsync](/api/types/Option.OptionAsync.md). If the input is a [None](/api/types/Option.None.md), the default value is returned. |

## Type Guards

| Function                                      | Description                                                                                             |
| --------------------------------------------- | ------------------------------------------------------------------------------------------------------- |
| [isNone](/api/functions/Option.isNone.md)     | Type guard to check if an [Option](/api/types/Option.Option.md) is a [None](/api/types/Option.None.md). |
| [isOption](/api/functions/Option.isOption.md) | Type guard to check if a value is an [Option](/api/types/Option.Option.md).                             |
| [isSome](/api/functions/Option.isSome.md)     | Type guard to check if an [Option](/api/types/Option.Option.md) is a [Some](/api/types/Option.Some.md). |

## Interop

| Function                                          | Description                                                                                                                                                                                                                                                                                                               |
| ------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [fromResult](/api/functions/Option.fromResult.md) | Converts a Result from [@praha/byethrow](https://github.com/praha-inc/byethrow) into an [Option](/api/types/Option.Option.md) or [OptionAsync](/api/types/Option.OptionAsync.md). A `Success` becomes a [Some](/api/types/Option.Some.md); a `Failure` becomes a [None](/api/types/Option.None.md), discarding the error. |
| [toResult](/api/functions/Option.toResult.md)     | Converts an [Option](/api/types/Option.Option.md) or [OptionAsync](/api/types/Option.OptionAsync.md) into a Result from [@praha/byethrow](https://github.com/praha-inc/byethrow). A [Some](/api/types/Option.Some.md) becomes a `Success`; a [None](/api/types/Option.None.md) becomes a `Failure` containing `err`.      |

## Utilities

| Function                              | Description                                                     |
| ------------------------------------- | --------------------------------------------------------------- |
| [pipe](/api/functions/Option.pipe.md) | Applies a sequence of functions to a value, from left to right. |
