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

# Function: maybe()

Executes a function and wraps its result in an [Option](/api/types/Option.Option.md) or [OptionAsync](/api/types/Option.OptionAsync.md).

Nullish values and Promise rejections produce [None](/api/types/Option.None.md); synchronous throws are not captured.

## Type Param

**F**

The function type to execute.

## Examples

**Synchronous Thunk**

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

const option = Option.maybe(() => document.querySelector('#app'));
// { type: 'Some', value: HTMLElement } or { type: 'None' }
```

**Asynchronous Thunk**

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

type Config = { host: string };

const option = await Option.maybe(() =>
  fetch('/api/config').then((response) => response.json() as Promise<Config>),
);
// { type: 'Some', value: Config }
```

## See

fn - For wrapping functions that take parameters.

## Call Signature

> **maybe**\<`F`>(`fn`): [`OptionAsync`](/api/types/Option.OptionAsync.md)\<`NonNullable`\<`Awaited`\<`ReturnType`\<`F`>>>>

### Type Parameters

#### F

`F` _extends_ () => `Promise`\<`any`>

### Parameters

#### fn

`F`

### Returns

[`OptionAsync`](/api/types/Option.OptionAsync.md)\<`NonNullable`\<`Awaited`\<`ReturnType`\<`F`>>>>

## Call Signature

> **maybe**\<`F`>(`fn`): [`Option`](/api/types/Option.Option.md)\<`NonNullable`\<`ReturnType`\<`F`>>>

### Type Parameters

#### F

`F` _extends_ () => `any`

### Parameters

#### fn

`F`

### Returns

[`Option`](/api/types/Option.Option.md)\<`NonNullable`\<`ReturnType`\<`F`>>>
