Hacker News new | ask | show | jobs
by DanielHB 478 days ago
General programming languages theory question, is one supposed to iterate over enum entries or is that considered an antipattern? I have found myself needing to do that a few times and it always felt a bit dirty.
2 comments

I wouldn't say it's an antipattern. E.g. listing all possible values of some user input field is a pretty natural use case for that.
No that’s fine and a reasonable thing to do . In fact, I’d say it is one of the main points of enums and one of my biggest gripes against Go is the lack of that capability
Swift can't handle it either, I had to write an extension to add that ability. Felt weird to me.
Yeah which is why I originally asked, some other languages don't really have a way to iterate over enums.