OvumDocs

Syntax & Semantics (Description)

Functions

Classes

Interfaces

Type Aliases

Namespaces & Preprocessor

Note: #define cannot be used to really define something, it is a way to control what code will be used.

Functional Objects (call)

Example:

interface CustomFunctional {
    call(a: Int?, b: Int?): Int
}

class DefinedFunctional {
    public var Multiplier: Int

    public fun DefinedFunctional(multiplier: Int): DefinedFunctional {
        this.Multiplier = multiplier
        return this
    }

    // Defines the callable behavior; pure body allowed
    public call(secondMultiplier: Int): Int = fun(secondMultiplier: Int): Int {
        return Multiplier * secondMultiplier
    }
}

val AddNullable: CustomFunctional = pure fun(a: Int?, b: Int?): Int {
    val aVal: int = a ?: 0  // Conversion from Int? to int
    val bVal: int = b ?: 0
    return aVal + bVal
}

fun Main(args: StringArray): Int {
    // Constructor call then functional call via `call`
    return AddNullable(2, DefinedFunctional(-1)(2))  // Implicit conversion from literals
}