Somewhat off topic, as you seem to be dealing with ragged arrays.  Are
you aware of https://github.com/mbauman/RaggedArrays.jl ?  Also there
are references to other, older implementations:
https://github.com/mbauman/RaggedArrays.jl/issues/2

On Wed, 2016-10-12 at 16:16, Tamas Papp <tkp...@gmail.com> wrote:
> 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