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

# unless

Returns a function that applies a transform only when a predicate fails,
otherwise returns the value unchanged.

Complement of `when`.

```typescript
const ensureArray = unless(Array.isArray, (v) => [v])
ensureArray(42) // [42]
ensureArray([1]) // [1]
```

## Usage

### `unless<T>(predicate: (value: T) => boolean, fn: (value: T) => T)`

Returns a function that applies a transform only when a predicate fails,
otherwise returns the value unchanged.

Complement of `when`.

```typescript
import { unless } from 'massaman'
// or:  import { unless } from 'massaman/function'

const ensureArray = unless(Array.isArray, (v) => [v])
ensureArray(42) // [42]
ensureArray([1]) // [1]
```

#### Parameters


predicate(value: T) => booleanrequired

the condition used to select behavior.


fn(value: T) => Trequired

the transformation to apply when `predicate` returns `false`.

#### Returns

a function that transforms values only when `predicate` returns `false`.

```typescript
(value: T) => T
```
