swh:1:snp:a72e953ecd624a7df6e6196bbdd05851996c5e40
Raw File
Tip revision: 37e6390c4509aab541f3396e3cea91f7b20790aa authored by Steven G. Johnson on 14 January 2015, 19:42:55 UTC
add type assertions to work around inference problem (fix #9772)
Tip revision: 37e6390
generator.jl
"""
    Generator(f, iter)

Given a function `f` and an iterator `iter`, construct an iterator that yields
the values of `f` applied to the elements of `iter`.
The syntax `f(x) for x in iter` is syntax for constructing an instance of this
type.
"""
immutable Generator{I,F}
    f::F
    iter::I
end

start(g::Generator) = start(g.iter)
done(g::Generator, s) = done(g.iter, s)
function next(g::Generator, s)
    v, s2 = next(g.iter, s)
    g.f(v), s2
end

collect(g::Generator) = map(g.f, g.iter)
back to top