SultanC
  1. Home
  2. Examples
  3. Generics

A generic function that works with any type

generics/identity.sn
def identity<T>(value: T): T {
    return value;
}

def main(): int {
    let number: int = identity(42);
    let truth: bool = identity(true);
    if (truth) { return number; };
    return 1;
}

Run it

With the interpreter, without compiling:

./build/sultanc run examples/en/generics/identity.sn

Or compile it to an executable:

./build/sultanc examples/en/generics/identity.sn -o build/example && ./build/example

Source on GitHub   All examples