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

# head (Functional Programming) es-toolkit

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

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

::: info

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

:::

## Usage

`head` returns the first value in the piped array. If the array is empty, it returns `undefined`.

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

pipe([1, 2, 3], head()); // => 1

pipe([], head()); // => undefined
```

#### Parameters

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

#### Returns

A function that maps a `readonly T[]` to its first value.

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


Source: es-toolkit

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