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.
Result: true
string/length
Returns the number of characters in a string.
Result: 4
string/concat
Concatenates two strings and returns the result.
Result: "lionized"
string/startsWith
Returns true when the first string starts with the second string.
Result: true
string/endsWith
Returns true when the first string ends with the second string.
Result: true
string/includes
Returns true when the first string contains the second string anywhere within it.
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.
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:
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.