Skip to content

Instantly share code, notes, and snippets.

@Hiosdra
Last active April 30, 2018 09:17
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Hiosdra/7d9ce2b035c968d0f535fb06b826fcc0 to your computer and use it in GitHub Desktop.
Save Hiosdra/7d9ce2b035c968d0f535fb06b826fcc0 to your computer and use it in GitHub Desktop.
//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