Skip to main content
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.
["func/bind", "fn", "obj"]
You can also supply initial arguments that are prepended on every call:
["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.
["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.
["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:
["object/call-method", "somePromise", "then",
  ["func/callback", ["lambda", ["result"], ["console/log", "result"]]]]
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.

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.
["func/partial", "fn", 1, 2]
A common use: creating a single-argument predicate from a two-argument function for use with match:
["match",
  "value",
  [["func/partial", "string/equals?", "user"], ["lambda", ["x"], "x"]],
  ["lambda", ["x"], null]]
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.