I want to safely be able to get an enum based on the value.
object UserType extends Enumeration {
type UserType = Value
val Anonymous, Member, Paid = Value
}
If I do:
UserType(100)
I get an error:
java.util.NoSuchElementException: key not found: 100
at scala.collection.MapLike$class.default(MapLike.scala:228)
at scala.collection.AbstractMap.default(Map.scala:59)
at scala.collection.mutable.HashMap.apply(HashMap.scala:65)
at scala.Enumeration.apply(Enumeration.scala:114)
... 32 elided
Is there a typesafe way to do this?