Skip to main content
The string module provides seven functions for working with text in Lion programs. All functions validate their inputs through Effect schemas and return typed errors when a non-string value is passed where a string is expected.

Functions

string/equals?

Returns true when both strings are identical.
["string/equals?", "a", "a"]
Result: true

string/length

Returns the number of characters in a string.
["string/length", "lion"]
Result: 4

string/concat

Concatenates two strings and returns the result.
["string/concat", "lion", "ized"]
Result: "lionized"

string/startsWith

Returns true when the first string starts with the second string.
["string/startsWith", "lion", "li"]
Result: true

string/endsWith

Returns true when the first string ends with the second string.
["string/endsWith", "lion", "on"]
Result: true

string/includes

Returns true when the first string contains the second string anywhere within it.
["string/includes", "lion", "io"]
Result: true

string/indexOf

Returns the index of the first occurrence of the second string within the first string. Returns Option.none when no match is found.
["string/indexOf", "lion", "o"]
Result: 2
string/indexOf uses Effect’s String.indexOf which returns an Option<number>. When the substring is absent the result is an Option.none() value, not -1. Use match with value/null? to handle the absent case, or check with value/object? if you need to inspect the Option tag directly.

Combining string functions

You can compose string functions inside a begin block to build up text step by step:
["begin",
  ["define", "greeting", ["string/concat", "Hello, ", "world"]],
  ["string/concat", "greeting", "!"]]
Result: "Hello, world!"
Use string/equals? as a predicate inside match to dispatch on string values, or combine it with func/partial to create a single-argument predicate for a specific string.