Created
June 29, 2023 07:25
-
-
Save ktgw0316/aab18f8b62b8d52711c3315210bcd8bc 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
| tailrec fun fact(n: Int, cont: (Int) -> Int = { it }): Int = when(n) { | |
| 1 -> cont(1) | |
| else -> fact(n - 1) { cont(n * it) } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment