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

# sample (Functional Programming) es-toolkit

Creates a function that returns a random value from an array. Use it with [`pipe`](https://massaman.dev/reference/fp/pipe.md).

```typescript
const result = pipe(array, sample());
```

::: info

Prefer the original es-toolkit [`sample`](https://massaman.dev/reference/array/sample.md) in ordinary code. Use this `fp` variant when composing transformations with [`pipe`](https://massaman.dev/reference/fp/pipe.md).

:::

## Usage

`sample` returns one random value from the piped array.

```typescript
import { pipe, sample } from 'es-toolkit/fp';

const value = pipe([1, 2, 3], sample());
// value is one of 1, 2, or 3.
```

#### Parameters

This function takes no arguments; call it as `sample()`.

#### Returns

A function that maps a `readonly T[]` to one random value.

```typescript
(array: readonly T[]) => T
```


Source: es-toolkit

Re-exported verbatim from [`es-toolkit`](https://es-toolkit.dev/fp/reference/sample.html). Implementation, edge cases, and performance behavior are owned upstream. This page mirrors the documentation at the pinned version; the linked source is authoritative.
