Skip to content

Instantly share code, notes, and snippets.

@dharasim
Created August 13, 2018 09:15
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 dharasim/5cd0f72fc7667082ab9502ff9b97cc31 to your computer and use it in GitHub Desktop.
Save dharasim/5cd0f72fc7667082ab9502ff9b97cc31 to your computer and use it in GitHub Desktop.
Fibs iterator in Julia v1.0
using Base.Iterators: take
import Base: iterate, IteratorSize, eltype
struct Fibs end
iterate(::Fibs, (i, j) = (1, 1)) = i, (j, i+j)
IteratorSize(::Type{Fibs}) = Base.IsInfinite()
eltype(::Type{Fibs}) = Int
# collect the first ten fibs in an array
collect(take(Fibs(), 10))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment