Created
May 6, 2021 10:22
-
-
Save channyeintun/b60c55560f6a4b0d670ddb355b470e38 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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