Skip to main content
The value module provides a set of type-checking predicates and the identity passthrough function. These predicates return a boolean and accept any value, making them the primary way to branch on value type inside match or cond expressions.

Predicates

value/function?

Returns true when the value is a function.
["value/function?", "myFn"]
Result: true when "myFn" resolves to a function in the environment.

value/number?

Returns true when the value is a number.
["value/number?", 1]
Result: true

value/string?

Returns true when the value is a string.
["value/string?", "lion"]
Result: true

value/boolean?

Returns true when the value is a boolean.
["value/boolean?", true]
Result: true

value/object?

Returns true when the value is an object and not null.
["value/object?", {"a": 1}]
Result: true

value/array?

Returns true when the value is an array.
["value/array?", ["array/make", 1, 2]]
Result: true

value/null?

Returns true when the value is exactly null.
["value/null?", null]
Result: true

Host-only predicates

Two additional predicates are available but are primarily useful when Lion programs work with host values injected through the environment:
  • value/undefined? — returns true when the value is undefined. JavaScript APIs sometimes return undefined where Lion programs expect null.
  • value/symbol? — returns true when the value is a JavaScript Symbol, which can appear in host objects or when using module.symbol sentinels.

value/identity

Returns its argument unchanged. This is useful as a no-op branch in match when you want to pass the matched value through without transformation.
["value/identity", 42]
Result: 42

Using predicates with match

Predicates are the natural arguments to match branches. Each branch pairs a predicate with a handler lambda:
["match",
  "value",
  ["value/number?", ["lambda", ["x"], ["number/add", "x", 1]]],
  ["value/string?", ["lambda", ["x"], ["string/concat", "x", "!"]]],
  ["lambda", ["x"], "x"]]
Use value/identity as the handler when you want a branch to pass the value through unmodified. It is more explicit than an inline ["lambda", ["x"], "x"] and signals intent clearly.