> ## Documentation Index
> Fetch the complete documentation index at: https://docs.lionlang.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# func module: function utilities in Lion

> Lion's func module provides bind, apply, partial application, and func/callback for converting Lion lambdas into plain JavaScript functions for host APIs.

The `func` module provides utilities for working with functions as first-class values in Lion. The most distinctive entry is `func/callback`, which converts a Lion lambda into a plain JavaScript function while preserving access to the Lion evaluation environment. This makes it possible to pass Lion logic to host APIs that expect ordinary callbacks.

## Functions

### `func/bind`

Binds a function to a `this` context and returns the bound function. Equivalent to `Function.prototype.bind` in JavaScript.

```json theme={null}
["func/bind", "fn", "obj"]
```

You can also supply initial arguments that are prepended on every call:

```json theme={null}
["func/bind", "fn", "obj", 1, 2]
```

***

### `func/apply`

Calls a function with a given `this` context and a list of arguments. Equivalent to `Function.prototype.apply`.

```json theme={null}
["func/apply", "fn", "obj", 1, 2]
```

***

### `func/callback`

Wraps a Lion lambda in a plain JavaScript function. When the resulting function is called (for example, by a Promise `.then`, an event listener, or an array method), the lambda runs inside the Lion evaluator with full access to the current environment.

```json theme={null}
["func/callback", ["lambda", ["x"], ["number/add", "x", 1]]]
```

This is especially important when a host API accepts a callback asynchronously — without `func/callback`, the lambda would run raw without the Lion environment context.

A practical pattern: passing a Lion lambda to a host `Promise`:

```json theme={null}
["object/call-method", "somePromise", "then",
  ["func/callback", ["lambda", ["result"], ["console/log", "result"]]]]
```

<Note>
  `func/callback` captures the current `LionEnvironmentService` context at the time of the call. The returned JavaScript function can be invoked any number of times and will always evaluate the lambda within that saved environment.
</Note>

***

### `func/partial`

Returns a new function with one or more arguments pre-applied. Calling the returned function appends any additional arguments after the pre-applied ones.

```json theme={null}
["func/partial", "fn", 1, 2]
```

A common use: creating a single-argument predicate from a two-argument function for use with `match`:

```json theme={null}
["match",
  "value",
  [["func/partial", "string/equals?", "user"], ["lambda", ["x"], "x"]],
  ["lambda", ["x"], null]]
```

<Tip>
  `func/partial` combined with `array/map` is a clean way to apply the same transformation with a fixed argument to every element in a list, without defining a named lambda.
</Tip>
