Comments (5)
Can you expand a little bit on what you mean by avoiding the overhead of overriding value? Current usage looks quite similar to what you've got there.
sealed abstract class LibraryItem(val value: Int, val name: String) extends IntEnumEntry
from enumeratum.
Currently, i have to override the method value
:
sealed abstract class LibraryItem(val value: Int, val name: String) extends IntEnumEntry {
override def value: Int = code
}
What I propose is a macro annotation for the parameter:
sealed abstract class Code(@Value val value: Int, val door: String) extends IntEnumEntry
Here it's not necessary to override the value
method...
from enumeratum.
Currently, i have to override the method
value
:sealed abstract class LibraryItem(val value: Int, val name: String) extends IntEnumEntry { override def value: Int = code }
What I propose is a macro annotation for the parameter:
sealed abstract class Code(@Value val value: Int, val door: String) extends IntEnumEntry
Here it's not necessary to override the
value
method...
Just to make sure I understand fully what you mean, you probably have this situation right now:
sealed abstract class LibraryItem(val code: Int, val name: String) extends IntEnumEntry {
override def value: Int = code
}
and what you want is
sealed abstract class Code(@Value val code: Int, val door: String) extends IntEnumEntry
?
from enumeratum.
Exactly! :)
from enumeratum.
I think it's do-able, but maybe it's a nice-to-have. Also, I don't think there's going to be much actual runtime performance overhead to the alias method once JIT kicks in.
If you would like to contribute this feature, please feel free to give it a try :) My only request is that it be done without adding dependencies and that error cases be handled nicely !
from enumeratum.
Related Issues (20)
- Enums with hierarchical structure HOT 2
- Avoid the use of `toString` for `enumEntry`? HOT 4
- [Scala 2] Compile-time stackoverflow with lots of enum values HOT 3
- Version 1.7.2 is not binary compatible with previous versions HOT 2
- Conflict with Scala 3 enums HOT 5
- Breaking compatibility should trigger a major version update HOT 2
- .
- enumeratum-json4s not available for Scala3? HOT 5
- Scala3: findValues fails to compile in nested sealed trait hierarchy HOT 1
- Scala 3: findValues fails to find entries extending types with type parameters HOT 1
- How to upgrade enumeratum-doobie to target v1.0.0-RC4 HOT 3
- Un-sealed abstract class in hierarchy gets ignored on Scala 3.x HOT 1
- Support play-json 3.0.x
- Members of enums nested in a class are not discovered in scala 3 HOT 1
- Derived `CirceEnum` codecs fail roundtrip on `case class` values HOT 4
- Enumeratum-Play 1.8.0 with Play 3 and Pekko cannot find play.api.libs.json.KeyReads at runtime HOT 2
- Override a single entry with custom name HOT 4
- ScalaDoc warnings in any code using the library
- Circe: Allow to decode enumerations more relaxed HOT 3
- Scala 3 ValueEnum only finds values if the value constructor parameter is first HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from enumeratum.