Skip to content

Making space for a swankier similar #26433

@mbauman

Description

@mbauman

A major task I'd love to accomplish in 1.x is a redesign of similar. This has been discussed in oh-so-many issues (primarily #18161, but also #25107), and I don't want to rehash those discussions all that much. The similar function currently has lots of methods on it, with three "chains" of fallbacks:

┌similar(::AbstractArray)
├similar(::AbstractArray, ::Union{Integer,AbstractUnitRange}...)
├similar(::AbstractArray, ::Tuple)
├similar(::AbstractArray, ::Type, ::Union{Integer,AbstractUnitRange}...)
╘similar(::Array, ::Type, ::Tuple) = Array()
┌similar(::Type{T}, ::Union{Integer,AbstractUnitRange}...)
╘similar(::Type{T}, ::Tuple) = T()
┌similar(f, ::Union{Integer,AbstractUnitRange}...)
╘similar(f, ::Tuple) = f()

(Where ::Array is a stand-in for any object that similar supports).

I'd like to bifurcate this into a value-domain and a type-domain, wherein the type-domain methods become the canonical endpoints. In order to make space for that, though, I believe we'll need to deprecate the second two pairs of chains. Those guys are there to support offset arrays. I believe similar(f, …) can be deprecated in favor of just putting methods on f. similar(Type{<:Array}, ...) is messier, though, since it feels wrong to have Array(undef, 2:3, 2:3) return something that's not an Array.

Metadata

Metadata

Assignees

No one assigned

    Labels

    arrays[a, r, r, a, y, s]deprecationThis change introduces or involves a deprecationspeculativeWhether the change will be implemented is speculative

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions