Skip to content

Instantly share code, notes, and snippets.

@channyeintun
Created May 6, 2021 10:22
Show Gist options
  • Select an option

  • Save channyeintun/b60c55560f6a4b0d670ddb355b470e38 to your computer and use it in GitHub Desktop.

Select an option

Save channyeintun/b60c55560f6a4b0d670ddb355b470e38 to your computer and use it in GitHub Desktop.
package localfunctions
fun first(): (Int) -> Int {
val func = fun(i: Int) = i + 1
return func
}
fun second(): (String) -> String {
val func2 = { s: String -> "$s!" }
return func2
}
fun third(): () -> String {
fun greet() = "Hi!"
return ::greet
}
fun fourth() = fun() = "Hi!"
fun fifth() = { "Hi!" }
fun main() {
val funRef1: (Int) -> Int = first()
val funRef2: (String) -> String = second()
val funRef3: () -> String = third()
val funRef4: () -> String = fourth()
val funRef5: () -> String = fifth()
funRef1(42)
funRef2("xyz")
funRef3()
funRef4()
funRef5()
first()(42)
second()("xyz")
third()()
fourth()()
fifth()()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment