Iterating collections

Citable collections should be usable with any Julia functions that recognize the Iterators conventions. We need to implement the Base.iterate method for our collection with two functions: one with a single parameter for our collection, and one with a second parameter you can use to maintain state through an iteration. The return value should be one element of the collection, or nothing when you reach the end.

Since our reading list is just a Vector, we can keep an index to the Vector in our state parameter, and trivially walk through the Vector by index value.

import Base: iterate

function iterate(rlist::ReadingList)
    (rlist.reff[1], 2)
end

function iterate(rlist::ReadingList, state)
    if state > length(rlist.reff)
        nothing
    else
        (rlist.reff[state], state + 1)
    end
end
iterate (generic function with 232 methods)
for item in rl
    println(item)
end
Main.Isbn10Urn("urn:isbn:022661283X")
Main.Isbn10Urn("urn:isbn:022656875X")
Main.Isbn10Urn("urn:isbn:022656875X")
Main.Isbn10Urn("urn:isbn:1108922036")
Main.Isbn10Urn("urn:isbn:0141395203")