4 ms·
Enums with functions. WTF
by samsaga2 5y ago
Enums with functions. WTF
- jpgvm 5y agoEnums are just special classes no? Why can't they have functions defined on them?
- TacoSteemers 5y agoJava enums also have functions. If they didn't we would need to write separate helper classes. Can you give a reason why we should not have them?
- kaba0 5y agoJava enums are essentially an in-built singleton pattern where only the given entries can exist. They are not necessarily analogous with sum types, even though rust sort of washes the two together.
- tempodox 5y agoIt's not unreasonable to group functions with the type they operate on.
- djxfade 5y agoMany languages has functions in Enums. They are just a specialized Class/Struct. Rust, Swift and Java among many languages has this.