I'm try to learn some Scala reading Programming Scala, by Dean Wampler.
I'm trying to replicate a code snippet about Enumeration
object Breed extends Enumeration {
val doberman = Value("Doberman Pinscher")
val yorkie = Value("Yorkshire Terrier")
val scottie = Value("Scottish Terrier")
val dane = Value("Great Dane")
val portie = Value("Portuguese Water Dog")
}
for (breed <- Breed) println(breed.id + "\t" + breed)
But, in the last line of code, I got this error:
value foreach is not a member of object Breed
Am I missing something? How can I solve?
You need to use .values
:
for (breed <- Breed.values) println(breed.id + "\t" + breed)
And why not make it a bit more scala-y
Breed.values.foreach(breed => println(breed.id + "\t" + breed));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With