> stream = XXX([1,2,3,4,5])
> collect(take(stream, 3))
[1,2,3]
> collect(take(stream, 2))
[4,5]
julia> function pull(itr,n)
state = start(itr)
for i=1:n state = next(itr,state)[2] ; end
(take(itr,n),rest(itr,state))
end
pull (generic function with 1 method)
julia> stream = 1:5
1:5
julia> head, tail = pull(stream,3)
(Base.Take{UnitRange{Int64}}(1:5,3),Base.Rest{UnitRange{Int64},Int64}(1:5,4))
julia> collect(head)
3-element Array{Int64,1}:
1
2
3
julia> collect(tail)
2-element Array{Any,1}:
4
5
julia> function pull(itr,n::Int)
state = start(itr)
head = eltype(itr)[]
while n>0 && !done(itr,state)
val,state = next(itr,state)
push!(head,val)
n-=1
end
(head,rest(itr,state))
end
pull (generic function with 2 methods)
julia> head,tail = pull([1,2,3,4,5],3)
([1,2,3],Base.Rest{Array{Int64,1},Int64}([1,2,3,4,5],4))
julia> collect(tail)
2-element Array{Any,1}:
4
5
| | |_| | | | (_| | | Version 0.5.0-dev+1137 (2015-11-04 03:36 UTC)
_/ |\__'_|_|_|\__'_| | Commit 95b7080 (5 days old master)
|__/ | x86_64-linux-gnu
julia> collect(1:3)
3-element Array{Int64,1}:
1
2
3
julia> collect(rest(1:3,start(1:3)))
3-element Array{Any,1}:
1
2
3