Skip to content

valtype should fallback to eltype #58081

Open
@MilesCranmer

Description

@MilesCranmer

I want to use valtype and keytype as a generic way of getting the value type and index type for a collection—and have the operation be compatible with dict-like collections. It seems some parts of this interface are missing so it would be nice to add fallbacks.

The valtype docstring says:

  • For Array
    • "Return the value type of an array. This is identical to eltype and is provided mainly for compatibility with the dictionary interface."
  • For Dict
    • "Get the value type of a dictionary type. Behaves similarly to eltype."

Based on this I would have guessed that valtype would fallback to eltype so that it can be compatible with any collection. Right now you run into things like

julia> eltype(Set{Float64})
Float64

julia> valtype(Set{Float64})
ERROR: MethodError: no method matching valtype(::Type{Set{Float64}})

which hurts the general use of this function.

Metadata

Metadata

Assignees

No one assigned

    Labels

    collectionsData structures holding multiple items, e.g. setsdesignDesign of APIs or of the language itselfiterationInvolves iteration or the iteration protocol

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions