Skip to content

Instantly share code, notes, and snippets.

@clemp6r
Created February 10, 2017 14:36
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 clemp6r/ef55749255284038a3660250e0a444eb to your computer and use it in GitHub Desktop.
Save clemp6r/ef55749255284038a3660250e0a444eb to your computer and use it in GitHub Desktop.
// inferred type is Sequence<Int>
val fibonacci = buildSequence {
yield(1)
var cur = 1
var next = 1
while (true) {
yield(next)
val tmp = cur + next
cur = next
next = tmp
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment