Skip to content

Instantly share code, notes, and snippets.

@ktgw0316
Created June 29, 2023 07:25
Show Gist options
  • Select an option

  • Save ktgw0316/aab18f8b62b8d52711c3315210bcd8bc to your computer and use it in GitHub Desktop.

Select an option

Save ktgw0316/aab18f8b62b8d52711c3315210bcd8bc to your computer and use it in GitHub Desktop.
継続渡しスタイルの末尾再帰関数
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