Skip to content

Instantly share code, notes, and snippets.

@slouc
Last active May 3, 2019 09:53
Show Gist options
  • Save slouc/fd61d394d8251f51fbe697fb872b5afe to your computer and use it in GitHub Desktop.
Save slouc/fd61d394d8251f51fbe697fb872b5afe to your computer and use it in GitHub Desktop.
def Y[A](func: (A => A) => (A => A)): (A => A) =
func(Y(func))(_)
def factorial: Int => Int =
Y {
(f: Int => Int) =>
(n: Int) =>
if (n <= 0) 1 else n * f(n - 1)
}
println(factorial(5)) // 120
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment