🧩Functions

Function Declaration Syntax

[exported] fun <functionName>[Generics]([Parameters]): <ReturnType> {
    <function body>
}

For syntax of Generics and Parameters - Common placeholders throughout documentation

Working Example

package main

import "fmt" as fmt
import "golang.org/x/exp/constraints" as constraints

fun isOver[T: constraints.Integer](a: T, b: T): Bool {
  return a > b
} 

fun createGreeting(firstName: String, lastName: String): String {
  return "Hello " + firstName + " " + lastName + "!"
}

fun main(): Unit {
  let age = 28
  let firstName = "John"
  let lastName = "Doe"
  let greeting = createGreeting(firstName, lastName)
  let isAdult = isOver(age, 18)
  fmt.println("Greeting:")
  fmt.println(greeting)
  fmt.println("Adult Status:")
  fmt.println(isAdult)
}

Last updated