I saw the following solution for an enum somewhere
object Day {
val values = new ArrayBuffer[Day]
case class Day(name:String) {
values += this
}
val MONDAY = new Day("monday")
val TUESDAY = new Day("tuesday")
}
This demonstrates what I am trying to go for EXCEPT there is a var hidden in the ArrayBuffer....that is kind of icky.
What I really want is a val lookupTable = Map() where when a request comes in, I can lookup "monday" and translate it to my enum MONDAY and use the enum throughout the software. How is this typically done. I saw sealed traits but didn't see a way to automatically make sure that when someone adds a class that extends it, that it would automatically be added to the lookup table. Is there a way to create a scala enum with lookup table?
A scala Enumeration seems close as it has a values() method but I don't see how to pass in the strings representing the days which is what we receive from our user and then translate that into an enum.
thanks, Dean
withNamemethod what you want? scala-lang.org/api/current/index.html#scala.Enumeration - KreverDaytype at runtime or is this going to be a kind of enum? If an enum, have you seen this question about macro-based sealed trait enums or this one? - Sean VieirawithNamescans the values of the enumeration looking for a match, so there's benefit to creating a lookup table. - cbmanica