Created
August 13, 2018 09:15
-
-
Save dharasim/5cd0f72fc7667082ab9502ff9b97cc31 to your computer and use it in GitHub Desktop.
Fibs iterator in Julia v1.0
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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