Skip to content

convert & promote_rule for Char and strings #25728

Closed
@StefanKarpinski

Description

@StefanKarpinski

Came up over here: #25515 (comment). I think we should consider adding something like:

promote_rule(::Type{Char}, ::Type{S}) where {S<:AbstractString} = S

convert(::Type{String}, c::Char) = string(c)
convert(::Type{S}, c::Char) where {S<:AbstractString} =
    convert(S, convert(String, c))

Previously when Char <: Integer this was considerably sketchier but that's not the case anymore.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions