Giter Club home page Giter Club logo

Comments (3)

randomstatistic avatar randomstatistic commented on July 17, 2024

I suppose it's worth noting that it's not the intermediate class so much as the intermediate constructor that's doing it. This works, for example:

abstract class StringEntryWithHelpers extends StringEnumEntry {
  //...
}


sealed abstract class Parameter(val value: String) extends StringEntryWithHelpers
object Parameters extends StringEnum[Parameter] {
  object FOO extends Parameter("foo")

  override def values = findValues
}

I'd hoped to hide the "val value" requirement was all.

from enumeratum.

lloydmeta avatar lloydmeta commented on July 17, 2024

Unfortunately, there is currently a strict requirement to have the value member of all of these value enums be implemented as a literal, in order for us to do the uniqueness check. There might be a way to sling enough macro magic to support what you're proposing (look up the class hierarchy to resolve that value is being implemented by a name member that is supplied as a literal at instantiation), but it seems like it'll be very difficult, and perhaps error-prone due to edge cases.

from enumeratum.

randomstatistic avatar randomstatistic commented on July 17, 2024

Alright, I'm using the phrasing in my second comment, I was just a little concerned that the "val value" was a bit of magic future maintainers might not notice. It's hard to decide between

sealed abstract class Parameter(val value: String) extends StringEnumEntry
// with
object FOO extends Parameter("foo")

and

sealed abstract class Parameter extends StringEnumEntry
// with
object FOO extends Parameter { val value = "foo" }

Not a huge deal either way though.

from enumeratum.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.