Functions are first-class values in CLS. They can be declared with full type signatures, assigned to variables, passed as arguments, returned from other functions, and composed into async pipelines. CLS supports named functions, arrow function expressions, generic functions with type inference, and async/await for deferred, concurrent workflows. Every function body is a block that closes withDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/elfrask/cls/llms.txt
Use this file to discover all available pages before exploring further.
};, and every statement inside that block ends with ;.
Named Function Declaration
Use thefunction keyword to declare a named function with typed parameters and an explicit return type. The return type follows the -> arrow after the parameter list.
Void Functions
A function with no meaningful return value is a procedure. Omit the-> Type annotation, or use the void keyword before the function name. Both forms are equivalent.
Default Parameters
Parameters can have default values. If a caller omits that argument, the default is used. Parameters with defaults must come after required parameters.The return Statement
return exits the current function and optionally passes a value back to the caller. In typed functions, the returned expression must be assignable to the declared return type.
Arrow Functions
Arrow functions are anonymous function expressions. They are written as(params) -> expression (expression form) or (params) -> { statements } (block form). Arrow functions capture their surrounding lexical scope and behave as closures.
Functions as Values
Named functions are first-class values. You can assign a declared function to a variable and call it through that variable, or pass it to higher-order functions.Function Type Signatures
The type of a function is written as(Param1, Param2, ...) -> ReturnType. You can use this in type annotations and create named aliases with alias.
Generic Functions
Functions can be parameterized with type variables declared in<> after the function name. The type checker infers the concrete type argument from the arguments passed at the call site.
Type arguments are inferred at the call site — you do not need to write
id<Int>(42). The type checker resolves T from the argument type and propagates it through the return type.Async / Await
CLS supports asynchronous programming throughasync function and the await expression. An async function returns a Promise immediately when called; its body is deferred until the Promise is consumed. await suspends the current async context until a Promise resolves and returns its value.
- Basic async/await
- async.delay
- async.all and async.race
async function creates a coroutine. Calling it does not execute the body immediately — it returns a Promise. The body runs only when the Promise is awaited or otherwise consumed. This means top-level async code should itself be inside an async function main.Recursion
Functions can call themselves. The type checker validates recursive calls the same way as any other call — the parameter and return types must be consistent.Visibility Modifiers
Functions support visibility and scope modifiers. These are meaningful for module exports and class members.| Modifier | Context | Description |
|---|---|---|
export | Module-level | Makes the function available when the module is imported |
public | Class member | Accessible from outside the class (default) |
private | Class member | Accessible only within the class body |
protected | Class member | Accessible within the class and subclasses |
static | Class member | Belongs to the class, not an instance; no me access |
Using export with imports
Using export with imports