Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: nameof(::Enum) #44323

Closed
Ellipse0934 opened this issue Feb 24, 2022 · 1 comment · Fixed by #44342
Closed

Feature Request: nameof(::Enum) #44323

Ellipse0934 opened this issue Feb 24, 2022 · 1 comment · Fixed by #44342
Labels
docs This change adds or pertains to documentation

Comments

@Ellipse0934
Copy link
Contributor

Ellipse0934 commented Feb 24, 2022

When I define an Enum. Say @enum Fruit apple=15 banana=27. Given the value I would like to get the name of the the enumerated type. One way to get this is.

julia> Base.Enums.namemap(Fruit)
Dict{Int32, Symbol} with 2 entries:
  5  => :apple
  19 => :banana

It would be convenient to have a method dedicated to this. I think nameof is suitable here. The resultant behaviour being
nameof(Fruit(5)) == :apple

I'm happy to implement it if this makes sense.

@simeonschaub
Copy link
Member

You can already use Symbol(Fruit(5)) for this. Could perhaps be documented better.

@simeonschaub simeonschaub added the docs This change adds or pertains to documentation label Feb 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs This change adds or pertains to documentation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants