google / built_value.dart

Immutable value types, enum classes, and serialization.
https://pub.dev/packages/built_value
BSD 3-Clause "New" or "Revised" License
870 stars 184 forks source link

EnumClass should use List instead of Set. #693

Open feinstein opened 5 years ago

feinstein commented 5 years ago

Currently EnumClass holds its values in a BuiltSet, but although we can convert it to a list using toList(), enum.values are lists and this would reflect better the Dart API.

Using lists is useful when we want the index of a enum value.

cpboyd commented 5 years ago

To that extent, it might be nice to add an index to the EnumClass, as Dart enums have by default (aka the ordinal in Java): https://dart.dev/guides/language/language-tour#enumerated-types

davidmorgan commented 5 years ago

Sorry for lack of response. Thanks for filing. Will likely look at this whenever I next take a long, hard look at enums :) not sure when that will be though.

tjarvstrand commented 4 years ago

+1 for this. Enums in most (all?) other implementations are ordered and can reliably be mapped to integers and back.