Skip to content

Commit

Permalink
fix result type of collect(T, itr)
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffBezanson committed Jun 21, 2016
1 parent 8ced94a commit 07a076a
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion base/array.jl
Expand Up @@ -215,7 +215,18 @@ _similar_for(c, T, itr, isz) = similar(c, T)
Return an array of type `Array{element_type,1}` of all items in a collection.
"""
collect{T}(::Type{T}, itr) = collect(Generator(T, itr))
collect{T}(::Type{T}, itr) = _collect(T, itr, iteratorsize(itr))

_collect{T}(::Type{T}, itr, isz::Union{HasLength,HasShape}) =
copy!(_similar_for(1:1 #= Array =#, T, itr, isz), itr)

function _collect{T}(::Type{T}, itr, isz::SizeUnknown)
a = _similar_for(1:1 #= Array =#, T, itr, isz)
for x in itr
push!(a,x)
end
return a
end

"""
collect(collection)
Expand Down

0 comments on commit 07a076a

Please sign in to comment.