Skip to content

Commit 809138f

Browse files
committed
fix #17439, update docs for collect to reflect dim-preserving behavior
1 parent c849f54 commit 809138f

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

base/array.jl

+5-2
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,8 @@ promote_rule{T,n,S}(::Type{Array{T,n}}, ::Type{Array{S,n}}) = Array{promote_type
202202
"""
203203
collect(element_type, collection)
204204
205-
Return an array of type `Array{element_type,1}` of all items in a collection.
205+
Return an Array with the given element type of all items in a collection or iterable.
206+
The result has the same shape and number of dimensions as `collection`.
206207
"""
207208
collect{T}(::Type{T}, itr) = _collect(T, itr, iteratorsize(itr))
208209

@@ -225,7 +226,9 @@ _similar_for(c, T, itr, isz) = similar(c, T)
225226
"""
226227
collect(collection)
227228
228-
Return an array of all items in a collection. For associative collections, returns Pair{KeyType, ValType}.
229+
Return an Array of all items in a collection or iterator. For associative collections, returns
230+
Pair{KeyType, ValType}. If the argument is array-like or is an iterator with the `HasShape()`
231+
trait, the result will have the same shape and number of dimensions as the argument.
229232
"""
230233
collect(itr) = _collect(1:1 #= Array =#, itr, iteratoreltype(itr), iteratorsize(itr))
231234

doc/stdlib/base.rst

+1
Original file line numberDiff line numberDiff line change
@@ -1446,3 +1446,4 @@ Internals
14461446
.. Docstring generated from Julia source
14471447
14481448
Compile the given function ``f`` for the argument tuple (of types) ``args``\ , but do not execute it.
1449+

doc/stdlib/collections.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -676,13 +676,13 @@ Iterable Collections
676676

677677
.. Docstring generated from Julia source
678678
679-
Return an array of all items in a collection. For associative collections, returns Pair{KeyType, ValType}.
679+
Return an Array of all items in a collection or iterator. For associative collections, returns Pair{KeyType, ValType}. If the argument is array-like or is an iterator with the ``HasShape()`` trait, the result will have the same shape and number of dimensions as the argument.
680680

681681
.. function:: collect(element_type, collection)
682682

683683
.. Docstring generated from Julia source
684684
685-
Return an array of type ``Array{element_type,1}`` of all items in a collection.
685+
Return an Array with the given element type of all items in a collection or iterable. The result has the same shape and number of dimensions as ``collection``\ .
686686

687687
.. function:: issubset(a, b)
688688
⊆(a,b) -> Bool

0 commit comments

Comments
 (0)