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

# ifElse

Returns a function that branches between two functions based on a predicate.

```typescript
const format = ifElse(
  (n: number) => n > 0,
  (n) => `+${n}`,
  (n) => `${n}`,
)
format(5)  // '+5'
format(-3) // '-3'
```

## Usage

### `ifElse<T, R>(predicate: (value: T) => boolean, onTrue: (value: T) => R, onFalse: (value: T) => R)`

Returns a function that branches between two functions based on a predicate.

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

const format = ifElse(
  (n: number) => n > 0,
  (n) => `+${n}`,
  (n) => `${n}`,
)
format(5)  // '+5'
format(-3) // '-3'
```

#### Parameters


predicate(value: T) => booleanrequired

the condition used to select behavior.


onTrue(value: T) => Rrequired

the function called when `predicate` returns `true`.


onFalse(value: T) => Rrequired

the function called when `predicate` returns `false`.

#### Returns

a function that dispatches each value to `onTrue` or `onFalse`.

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