Giter Club home page Giter Club logo

Comments (3)

lloydmeta avatar lloydmeta commented on September 18, 2024

Hi there,

There's nothing automatic that will do it for you sadly; the macro literally only searches the body it's in at the level that it's in (doesn't search deeper). This is what I think could work, but I understand it might not appeal to you because of the manual concatenation:

(Please excuse the use of Ammonite)

@ import $ivy.`com.beachape::enumeratum:1.5.7`, enumeratum._ 
import $ivy.$                               , enumeratum._
@ {
sealed trait BaseGroup extends EnumEntry
object BaseGroup extends Enum[BaseGroup] {
  // Manually concatenate
  val values = findValues ++ GroupA.values
  case object metricA extends BaseGroup
  case object metricB extends BaseGroup
  case object metricC extends BaseGroup
}

sealed trait GroupA extends BaseGroup
object GroupA extends Enum[GroupA] {
  val values = findValues
  case object metricD extends GroupA
  case object metricE extends GroupA
}
}

@ BaseGroup.values 
res2: collection.immutable.IndexedSeq[BaseGroup] = Vector(metricA, metricB, metricC, metricD, metricE)

from enumeratum.

meddulla avatar meddulla commented on September 18, 2024

The idea was actually the other way round, that there would be a GroupA, GroupB, etc that would all get the common metrics from the BaseGroup, and not that BaseGroup would have them all. But either way, yeah, was hoping that something better would be possible. Anyway, thanks for your input.

from enumeratum.

lloydmeta avatar lloydmeta commented on September 18, 2024

I see. I can kind of see what you're trying to do, but that doesn't make much sense from a type-perspective; you would end up having values in the enum "subtypes" that have a less precise type of IndexedSeq[BaseGroup] as opposed to the more precise type (e.g. IndexedSeq[GroupA], IndexedSeq[GroupB]). This arguably ends up making code less safe..

Given this type-level dilemma, it might be that enums aren't the right tool to solve the problem you have :)

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.