Skip to content

Instantly share code, notes, and snippets.

@inopinatus
Created March 23, 2020 04:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save inopinatus/0ad30ed1a65193c034e8ed0c0e92548e to your computer and use it in GitHub Desktop.
Save inopinatus/0ad30ed1a65193c034e8ed0c0e92548e to your computer and use it in GitHub Desktop.
yfib
y = ->(f) {
->(x) { x.(x) }.(
->(x) { f.(->(v) { x.(x).(v) }) } )
}
fib = y.(->(f) {
->(n) { n < 2 ? Array(0..n) : f[n-1].then { _1 << _1[-1] + _1[-2] } }
})
fib[6] #=> [0, 1, 1, 2, 3, 5, 8]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment