Skip to content

Docs say collect will return an Array, but implementation is different #36448

Open
@davidanthoff

Description

@davidanthoff

The docs for collect(collection) says that it will return an Array (see here). The implementation, though, calls similar(Array{T}, axes(A)) to create the container that will be returned, and that is explicitly not required to return an Array (see here).

The net effect is that for example

using StaticArrays

x = collect(i for i in SA[1,2])

will not return an Array.

I think either the docs should be updated to say that collect will return an AbstractArray, or the collect implementation should be changed to actually always return an Array, no matter what.

It certainly would be very handy to have a function in base that one can call on a collection that guarantees that one gets an Array, and not some custom array type.

Metadata

Metadata

Assignees

No one assigned

    Labels

    arrays[a, r, r, a, y, s]designDesign of APIs or of the language itself

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions