For example, I want

collect_ragged(countfrom(1), [2,3,4])

to return

3-element Array{Any,1}:
 [1,2]    
 [3,4,5]  
 [6,7,8,9]

I implemented it as

function collect_ragged(iterator, lengths)
    result = Vector(length(lengths))
    s = start(iterator)
    for (i,l) in enumerate(lengths)
        v = Vector{eltype(s)}(l)
        for j in 1:l
            (v[j],s) = next(iterator, s)
        end
        result[i] = v
    end
    result
end

bit I am wondering if there is a more elegant solution.

Reply via email to