For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt, and this page is available as Markdown at /reference/function/unless.md.

unless

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

Complement of when.

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.

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.

(value: T) => T