Skip to content

Commit

Permalink
fix List iteration
Browse files Browse the repository at this point in the history
and add a test
  • Loading branch information
pfitzseb committed Aug 27, 2018
1 parent 4324734 commit 66b4a76
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
3 changes: 1 addition & 2 deletions src/Lazy.jl
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,7 @@ setindex!(xs::LinkedList, v, i::Integer) = i <= 1 ? xs.first = v : (tail(xs)[i-1
setindex!(xs::LazyList, v, i::Integer) = i <= 1 ? realise(xs)[1] = v : (tail(xs)[i-1] = v)

# Iteration over a list holds on to the head
Base.iterate(xs::List) = xs, xs
function Base.iterate(::List, xs::List)
function Base.iterate(L::List, xs::List=L)
isempty(xs) && return nothing
first(xs), tail(xs)
end
Expand Down
1 change: 1 addition & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ using Test
@test list(1,2,list(3,4))[3] == list(3, 4)
@test list(list(1), list(2))[1] == list(1)
@test reductions(+, 0, list(1, 2, 3)) == list(1, 3, 6)
@test [i for i in @lazy[1,2,3]] == [1,2,3]
end

@testset "Fibs" begin
Expand Down

0 comments on commit 66b4a76

Please sign in to comment.