import { Meta } from '@storybook/addon-docs/blocks'

<Meta title='@dxtmisha/en/functional-basic/Functions/executeFunction - Execute function or return value'/>

# `executeFunction`

A flexible utility designed to handle arguments that can be either a static value or a function. If the provided argument is a function, `executeFunction` invokes it with the specified arguments and returns the result. Otherwise, it returns the argument itself.

This pattern is highly effective for implementing lazy evaluation, dynamic default values, or configuration properties that can be either fixed or computed.

**Parameters:**
- `callback: T | ((...args: any[]) => T)` — The value to process. Can be a literal value or a function returning type `T`.
- `...args: any[]` (optional) — Arguments to pass to the function if `callback` is callable.

**Returns:**
`T` — The result of the function execution or the raw value.

```typescript
import { executeFunction } from '@dxtmisha/functional-basic'

// 1. Static value handling
console.log(executeFunction('Hello')) // 'Hello'

// 2. Dynamic execution
const getLabel = (prefix: string) => `${prefix}: Dynamic Label`
console.log(executeFunction(getLabel, 'Admin')) // 'Admin: Dynamic Label'

// 3. Conditional logic in caller
const value = Math.random() > 0.5 ? 'Static' : () => 'Computed'
console.log(executeFunction(value)) // either 'Static' or 'Computed'
```
