# Using iterator in Julia 0.7

**URL:** <https://discourse.julialang.org/t/using-iterator-in-julia-0-7/11546>\
**Category:** General Usage\
**Created:** [June 8, 2018, 6:58pm UTC](https://discourse.julialang.org/t/using-iterator-in-julia-0-7/11546 "2018-06-08T18:58:14Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![00vareladavid](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/00vareladavid/32/23521_2.png) [@00vareladavid](https://discourse.julialang.org/u/00vareladavid)\
**Post date:** [June 8, 2018, 6:58pm UTC](https://discourse.julialang.org/t/using-iterator-in-julia-0-7/11546/1 "2018-06-08T18:58:14Z")

</div>

I’m trying to implement the iterator interface on a toy linked list implementation. I believe I’m getting it right, but I keep getting an error I don’t know how to handle. I’m using this [reference](https://docs.julialang.org/en/latest/manual/interfaces/#man-interface-iteration-1). I tried unsuccessfully to find examples, so I’m at a dead end for now.

The error is: `no method matching iterate(::LinkedList{Int64})`

My code:

```julia
mutable struct LLNode{T}
    data::T
    next::Union{LLNode{T},Nothing}
    prev::Union{LLNode{T},Nothing}
end
LLNode(d::T) where {T} = LLNode{T}(d,nothing,nothing)

mutable struct LinkedList{T}
    count::Int
    head::Union{LLNode{T},Nothing}
    tail::Union{LLNode{T},Nothing}
    #LinkedList{T}() where {T} = LinkedList(0,nothing,nothing)
end

is_empty(ll::LinkedList) = (ll.count == 0)
is_singular(ll::LinkedList) = (ll.count == 1)

function ll_push!(ll::LinkedList{T}, val::T) where {T}
    x::LLNode{T} = LLNode(val)
    if is_empty(ll)
        ll.head = ll.tail = x
    else
        x.prev = ll.tail
        ll.tail = ll.tail.next = x
    end

    ll.count += 1
end

function iterate(ll::LinkedList{T}) where {T}
    if ll.head === nothing
        return nothing
    end
    return (ll.head.data, ll.head)
end

function iterate(ll::LinkedList{T}, x::LLNode{T}) where {T}
    if x.next === nothing
        return nothing
    end
    return (x.next.data, x.next)
end

function print_list(ll::LinkedList{T}) where {T}
    for x in ll
        println(x.data)
    end
end

ll = LinkedList{Int}(0,nothing,nothing)
ll_push!(ll,1)
ll_push!(ll,2)
ll_push!(ll,3)
print_list(ll)

```

---

<div class="post-metadata">

**Author:** ![mbauman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mbauman/32/31082_2.png) [@mbauman](https://discourse.julialang.org/u/mbauman)\
**Post date:** [June 8, 2018, 6:59pm UTC](https://discourse.julialang.org/t/using-iterator-in-julia-0-7/11546/2 "2018-06-08T18:59:27Z")

</div>

Are you importing `iterate` for method extension with an `import Base: iterate`? Or, alternatively, just use `function Base.iterate(…) …` at the definition site.

---

<div class="post-metadata">

**Author:** ![00vareladavid](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/00vareladavid/32/23521_2.png) [@00vareladavid](https://discourse.julialang.org/u/00vareladavid)\
**Post date:** [June 8, 2018, 7:12pm UTC](https://discourse.julialang.org/t/using-iterator-in-julia-0-7/11546/3 "2018-06-08T19:12:14Z")

</div>

Yes, that was my issue. Thank you for pointing that out
