{"action":"opened","issue":{"url":"https://api.github.com/repos/lloydmeta/enumeratum/issues/198","repository_url":"https://api.github.com/repos/lloydmeta/enumeratum","labels_url":"https://api.github.com/repos/lloydmeta/enumeratum/issues/198/labels{/name}","comments_url":"https://api.github.com/repos/lloydmeta/enumeratum/issues/198/comments","events_url":"https://api.github.com/repos/lloydmeta/enumeratum/issues/198/events","html_url":"https://github.com/lloydmeta/enumeratum/issues/198","id":368557964,"node_id":"MDU6SXNzdWUzNjg1NTc5NjQ=","number":198,"title":"How to mix ValueEnumEntry's value with EnumEntry's entryName ?","user":{"login":"zawlazaw","id":13029914,"node_id":"MDQ6VXNlcjEzMDI5OTE0","avatar_url":"https://avatars1.githubusercontent.com/u/13029914?v=4","gravatar_id":"","url":"https://api.github.com/users/zawlazaw","html_url":"https://github.com/zawlazaw","followers_url":"https://api.github.com/users/zawlazaw/followers","following_url":"https://api.github.com/users/zawlazaw/following{/other_user}","gists_url":"https://api.github.com/users/zawlazaw/gists{/gist_id}","starred_url":"https://api.github.com/users/zawlazaw/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zawlazaw/subscriptions","organizations_url":"https://api.github.com/users/zawlazaw/orgs","repos_url":"https://api.github.com/users/zawlazaw/repos","events_url":"https://api.github.com/users/zawlazaw/events{/privacy}","received_events_url":"https://api.github.com/users/zawlazaw/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-10-10T08:52:13Z","updated_at":"2018-10-10T08:52:13Z","closed_at":null,"author_association":"NONE","body":"Currently, `EnumEntry` allows to override the `entryName`, and `ValueEnumEntry` allows to assign an integer `value` to the entry (e.g., an integer via `IntEnumEntry`). I would like to identify an enum entry by *both* an integer and a name.\r\n\r\nBy trial and error I found out that this can be achieved by mixing both traits as follows:\r\n\r\n\tsealed abstract class Loglevel(override val value: Int) extends IntEnumEntry with EnumEntry\r\n\r\n\tobject Loglevel extends IntEnum[Loglevel] with Enum[Loglevel] {\r\n\r\n\t  import scala.language.experimental.macros\r\n\t  override protected def findValues: IndexedSeq[Loglevel] = macro EnumMacros.findValuesImpl[Loglevel]\r\n\r\n\t  val values = findValues\r\n\r\n\t  case object Debug extends Loglevel(value = 10)\r\n\t  case object Info extends Loglevel(value = 100)\r\n\t  case object Warning extends Loglevel(value = 1000)\r\n\t}\r\n\r\n\tobject Playground extends App {\r\n\r\n\t  /*\r\n\t   * Everything seems to work fine:\r\n\t   */\r\n\r\n\t  println(Loglevel.withValue(10)) // gives \"Debug\"\r\n\t  println(Loglevel.withNameInsensitive(\"debug\")) // gives \"Debug\"\r\n\r\n\t  val ll: Loglevel = Loglevel.Info\r\n\r\n\t  ll match {\r\n\t\tcase Loglevel.Debug => \"is debug\"\r\n\t\tcase Loglevel.Info => \"is info\"\r\n\t\tcase Loglevel.Warning => \"is warning\"\r\n\t  }\r\n\r\n\t  ll.value match {\r\n\t\tcase 10 => \"is debug\"\r\n\t\tcase 100 => \"is info\"\r\n\t\tcase 1000 => \"is warning\"\r\n\t\tcase _ => \"is unknown\"\r\n\t  }\r\n\t}\r\n\r\nHowever, since I do not know much about macros, I have no clue whether overriding `findValues` in that way could break something. So, I have two questions:\r\n1. Is it ok (in the sense of \"upwards-compatible\", and \"conflict-free\" with Play, Json, etc.) to mix these traits as shown above?\r\n2. Is there an easier way (in the sense of \"less boilerplate\") to achieve that kind of \"`NamedIntEnum`\" ?"}}
{"actor":{"display_login":"zawlazaw"}}