Skip to content

Instantly share code, notes, and snippets.

@renaudcerrato
Last active February 9, 2019 08:14
Show Gist options
  • Save renaudcerrato/538ac05b78102fe02cf874b332af369f to your computer and use it in GitHub Desktop.
Save renaudcerrato/538ac05b78102fe02cf874b332af369f to your computer and use it in GitHub Desktop.
Kotlin Functions (simple)
// block body
fun sum(a: Int, b: Int) : Int {
return a + b
}
// expression body, inferred return type
fun sum(a: Int, b: Int) = a + b
// variable of a function type
val foo: (Int, Int) -> Int = sum
// variable of a nullable function type
var foo: ((Int, Int) -> Int)? = sum
// Unit is Kotlin's void (it is optional)
fun hello(name: String) : Unit {
println("Hello $name!")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment