Skip to content

Types & Conversions ​

Functions for type conversions, string manipulation, and mathematical operations.

Output ​

print ​

Signature: print(value: T) -> Unit

Prints any value to standard output.

Type Conversions ​

to_string ​

Signature: to_string(value: T) -> String

Converts any value to its string representation.

to_stringf ​

Signature: to_stringf(value: Float) -> String

Converts a float to a string. Useful when you need explicit float-to-string conversion.

to_float ​

Signature: to_float(value: Int) -> Float

Converts an integer to a floating-point number.

to_int ​

Signature: to_int(value: String) -> Option[Int]

Attempts to parse a string as an integer. Returns Some(n) on success, None on failure.

parse_float ​

Signature: parse_float(value: String) -> Option[Float]

Attempts to parse a string as a float. Returns Some(f) on success, None on failure.

length ​

Signature: length(value: Any) -> Int

Returns the length of a string or list.

String Operations ​

split ​

Signature: split(delimiter: String, str: String) -> List[String]

Splits a string by the given delimiter. The data-last argument order makes this function pipe-friendly.

join ​

Signature: join(delimiter: String, strings: List[String]) -> String

Joins a list of strings with the given delimiter. The data-last argument order makes this function pipe-friendly.

substring ​

Signature: substring(start: Int, length: Int, str: String) -> String

Extracts a substring starting at the given index with the specified length. The data-last argument order makes this function pipe-friendly.

trim ​

Signature: trim(str: String) -> String

Removes leading and trailing whitespace from a string.

to_uppercase ​

Signature: to_uppercase(str: String) -> String

Converts all characters to uppercase.

to_lowercase ​

Signature: to_lowercase(str: String) -> String

Converts all characters to lowercase.

contains ​

Signature: contains(substring: String, str: String) -> Bool

Returns true if the string contains the given substring. The data-last argument order makes this function pipe-friendly.

starts_with ​

Signature: starts_with(prefix: String, str: String) -> Bool

Returns true if the string starts with the given prefix. The data-last argument order makes this function pipe-friendly.

ends_with ​

Signature: ends_with(suffix: String, str: String) -> Bool

Returns true if the string ends with the given suffix. The data-last argument order makes this function pipe-friendly.

replace ​

Signature: replace(from: String, to: String, str: String) -> String

Replaces all occurrences of from with to in the string. The data-last argument order makes this function pipe-friendly.

char_at ​

Signature: char_at(index: Int, str: String) -> Option[String]

Returns the character at the given index as a single-character string, or None if the index is out of bounds. The data-last argument order makes this function pipe-friendly.

Math Functions ​

abs / absf ​

Signatures:

  • abs(n: Int) -> Int
  • absf(n: Float) -> Float

Returns the absolute value of a number.

sqrt ​

Signature: sqrt(n: Float) -> Float

Returns the square root of a number.

pow ​

Signature: pow(base: Float, exponent: Float) -> Float

Returns base raised to the power of exponent.

sin / cos ​

Signatures:

  • sin(radians: Float) -> Float
  • cos(radians: Float) -> Float

Trigonometric functions. Arguments are in radians.

exp / log ​

Signatures:

  • exp(n: Float) -> Float - e raised to the power of n
  • log(n: Float) -> Float - Natural logarithm of n

floor / ceil ​

Signatures:

  • floor(n: Float) -> Int - Rounds down to nearest integer
  • ceil(n: Float) -> Int - Rounds up to nearest integer

pi ​

Signature: pi() -> Float

Returns the mathematical constant pi (approximately 3.14159...).

random ​

Signature: random() -> Float

Returns a random floating-point number between 0.0 (inclusive) and 1.0 (exclusive).

Comparison ​

compare ​

Signature: compare(a: T, b: T) -> Ordering

Compares two values of the same type. Returns Less, Equal, or Greater.

Predicate Functions ​

These functions are useful in refinement type predicates.

is_power_of_2 ​

Signature: is_power_of_2(n: Int) -> Bool

Returns true if the given integer is a power of 2 (1, 2, 4, 8, 16, ...).

kettle
type PowerOf2 = Int as n | is_power_of_2(n)

normalized ​

Signature: normalized(list: List[Float]) -> Bool

Returns true if the sum of squares of the list elements equals 1 (within floating-point tolerance). Useful for verifying unit vectors.

kettle
type UnitVector = List[Float] as xs | normalized(xs)

Utility Functions ​

id ​

Signature: id(value: T) -> T

The identity function. Returns its argument unchanged. Useful in higher-order function contexts.

Option Functions ​

Functions for working with Option[T] values.

is_some ​

Signature: is_some(opt: Option[T]) -> Bool

Returns true if the option contains a value.

is_none ​

Signature: is_none(opt: Option[T]) -> Bool

Returns true if the option is None.

unwrap ​

Signature: unwrap(opt: Option[T]) -> T

Extracts the value from a Some. Fails at runtime if the option is None.

unwrap_or ​

Signature: unwrap_or(default: T, opt: Option[T]) -> T

Returns the contained value or the default if None. The data-last argument order makes this function pipe-friendly.

Result Functions ​

Functions for working with Result[T, E] values.

is_ok ​

Signature: is_ok(result: Result[T, E]) -> Bool

Returns true if the result is Ok.

is_err ​

Signature: is_err(result: Result[T, E]) -> Bool

Returns true if the result is Err.

See Also ​