Skip to content

Remove arbitrary use case of enum from documentation #5016

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 0 additions & 29 deletions docs/docs/reference/enums/enums.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,35 +88,6 @@ object Planet {
println(s"Your weight on $p is ${p.surfaceWeight(mass)}")
}
}
```
### A specific use case of enum

Two enums can be combined into a different type as shown below:

```scala

trait Animal
object Animal {
def enumValues: Iterable[Animal] = Dog.enumValues ++ Cat.enumValues
def enumValueNamed = Dog.enumValueNamed ++ Cat.enumValueNamed
}

enum Dog extends Animal {
case GermanShepherd, Labrador, Boxer
}

enum Cat extends Animal {
case PersianCat, Ragdoll, ScottishFold
}

object Main {
def main(args: Array[String]): Unit = {
val values: Iterable[Animal] = Animal.enumValues
val boxer_dog: Animal = Animal.enumValueNamed("Boxer")
val ragdoll_cat: Animal = Animal.enumValueNamed("Ragdoll")
}
}

```

### Implementation
Expand Down
33 changes: 33 additions & 0 deletions tests/run/i4961.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
trait Animal
object Animal {
def enumValues: Iterable[Animal] = Dog.enumValues ++ Cat.enumValues
def enumValueNamed = Dog.enumValueNamed ++ Cat.enumValueNamed
}

enum Dog extends Animal {
case GermanShepherd, Labrador, Boxer
}

enum Cat extends Animal {
case PersianCat, Ragdoll, ScottishFold
}

object Test {
import Dog._
import Cat._

def main(args: Array[String]): Unit = {
val values = List(
GermanShepherd,
Labrador,
Boxer,
PersianCat,
Ragdoll,
ScottishFold
)

assert(Animal.enumValues == values)
assert(Animal.enumValueNamed("Boxer") == Boxer)
assert(Animal.enumValueNamed("Ragdoll") == Ragdoll)
}
}