Skip to content

define emptymutable for all sets so that map, filter etc return right type #632

Open

Description

@oxinabox

We should define Base.emptymutable for all out mutable AbstractSet subtypes.

Consider SortedSet

julia> filter(isodd, SortedSet((1,2,3,4)))
Set{Int64} with 2 elements:
  3
  1

But if we define:

Base.emptymutable(s::SortedSet{T}, ::Type{U}=T) where {T,U} = SortedSet{U}()

then we get

julia> filter(isodd, SortedSet((1,2,3,4)))
SortedSet{Int64,Base.Order.ForwardOrdering} with 2 elements:
  1
  3

see also
JuliaLang/julia#34677 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions