Suppose I have enumeration:
object WeekDay extends Enumeration {
type WeekDay = Value
val Mon, Tue, Wed, Thu, Fri, Sat, Sun = Value
}
I would like to be able to convert String to WeekDay value and this is fine with:
scala> WeekDay.withName("Tue")
res10: WeekDay.Value = Tue
But if I pass some 'unknown' value, I'm getting exception:
scala> WeekDay.withName("Ou")
java.util.NoSuchElementException: None.get
at scala.None$.get(Option.scala:322)
at scala.None$.get(Option.scala:320)
at scala.Enumeration.withName(Enumeration.scala:124)
... 32 elided
Is there some elegant way of safely convert String to Enumeration value?