Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
//Type inference, global variable and function as object
var x = fun(x:Int, y:Int): Int {
return x + y
//Top level functions
fun main(args: Array<String>) {
println("Hello world")
//Function as parameter and expression-bodied methods
fun adding(a: Int, b: Int, addingFunction: (Int, Int) -> Int) = addingFunction.invoke(a, b)
fun example1() {
//Nested functions
fun increment(i: Int, incrementFunction: (i: Int) -> Int) = incrementFunction.invoke(i)
//Beautiful notation
val incrementedValue = increment(1) { it + 1 }
//Returning functions
fun returningFunction() = fun(s: String) = s.length
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment