lampepfl / dotty-feature-requests

Historical feature requests. Please create new feature requests at https://github.com/lampepfl/dotty/discussions/new?category=feature-requests
31 stars 2 forks source link

Add alternative to `values` for enums that return immutable indexed sequence without defensive copying #230

Closed bjornregnell closed 1 year ago

bjornregnell commented 3 years ago

The method values on enums returns an Array that gets allocated at each call. This is inline with how Java enums work.

It would be nice if an alternative method existed, for example called seq, that returned an ArraySeq that is just a shared immutable reference to the already allocated sequence of values, not requiring a defensive copying. This would be more efficient and also more Scala-idomatic.

bjornregnell commented 3 years ago

See also gitter conversation here: https://gitter.im/scala/contributors?at=60f5bcd9049a0c3e5380f64d