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

# sampleSize (Functional Programming) es-toolkit

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

```typescript
const result = pipe(array, sampleSize(size));
```

::: info

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

:::

## Usage

`sampleSize` returns `size` random values from the piped array without repeating the same array position.

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

const values = pipe([1, 2, 3, 4], sampleSize(2));
// values has length 2 and contains values from the input array.
```

#### Parameters


sizenumberrequired

The number of random values to return.

#### Returns

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

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

#### Throws

Throws an error if `size` is greater than the length of the piped array.


Source: es-toolkit

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