Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions base/abstractarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1198,10 +1198,12 @@ end
"""
copymutable(a)

Make a mutable copy of an array or iterable `a`. For `a::Array`,
this is equivalent to `copy(a)`, but for other array types it may
differ depending on the type of `similar(a)`. For generic iterables
this is equivalent to `collect(a)`.
Make a mutable copy of an array or iterable `a`. The result should have the same content as
`a`, but support mutation. For `Array`s and most iterables this is equivalent to
`collect(a)`, but for other array types it may differ depending on the type of `similar(a)`.

To change the behavior of `copymutable` on a custom collection, define [`similar`](@ref)
for that collection.

# Examples
```jldoctest
Expand All @@ -1213,6 +1215,20 @@ julia> Base.copymutable(tup)
1
2
3

julia> using StaticArrays

julia> s = SVector{3}(1,2,3)
3-element SVector{3, Int64} with indices SOneTo(3):
1
2
3

julia> Base.copymutable(s)
3-element MVector{3, Int64} with indices SOneTo(3):
1
2
3
```
"""
function copymutable(a::AbstractArray)
Expand Down
1 change: 1 addition & 0 deletions base/exports.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1114,6 +1114,7 @@ public
split_rest,
tail,
checked_length,
copymutable,

# Loading
DL_LOAD_PATH,
Expand Down
3 changes: 2 additions & 1 deletion base/sort.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1475,7 +1475,8 @@ end
Variant of [`sort!`](@ref) that returns a sorted copy of `v` leaving `v` itself unmodified.

Returns something [`similar`](@ref) to `v` when `v` is an `AbstractArray` and uses
[`collect`](@ref) to support arbitrary non-`AbstractArray` iterables.
[`collect`](@ref) to support arbitrary non-`AbstractArray` iterables. some types have
specialized versions of `sort`, such as `NTuples` (`sort(::NTuple)` returns an `NTuple`)

!!! compat "Julia 1.10"
`sort` of arbitrary iterables requires at least Julia 1.10.
Expand Down
1 change: 1 addition & 0 deletions doc/src/base/collections.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ Base.tail
Base.step
Base.collect(::Any)
Base.collect(::Type, ::Any)
Base.copymutable(::Any)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm hesitant to make copymutable public now, at least as long as it's not implemented for AbstractDict.

Base.filter
Base.filter!
Base.replace(::Any, ::Pair...)
Expand Down