Description
I wonder whether collect()
isn't always equivalent to Vector()
, and could therefore be merged into it:
julia> methods(collect)
JuliaLang/julia#3 methods for generic function "collect":
collect(r::Range{T<:Any}) at range.jl:753
collect{T}(::Type{T}, itr) at array.jl:217
collect(itr) at array.jl:224
The method for Range
returns a vector, so it could be replaced with Array()
, as both call vcat()
in the end. convert(Vector, ...)
currently fails and should be fixed.
The methods for general iterables are more complex, but they essentially always create an Array
too. Even when they call similar()
, it's on a 1:1
range, so they actually create a Vector
. So the collect()
machinery could be moved to Array()
/Vector()
to make them support conversion from any iterable.
This issue is related to discussions regarding similar()
(JuliaLang/LinearAlgebra.jl#271). Indeed, Julia provides a few functions which appear to behave differently, but in practice behave like Array
, and callers end up depending on this assumption. This makes the API more complex and less explicit.
See also JuliaLang/LinearAlgebra.jl#231 about merging full
into Array
.