Skip to content
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

Make enum example serializable #1271

Merged
merged 1 commit into from
Sep 12, 2022
Merged
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
10 changes: 7 additions & 3 deletions examples/src/main/scala/shapeless/examples/enum.scala
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,12 @@ object ScalaEnumDemo /*extends App*/ {
//
object ShapelessEnumDemo extends App {
// ADT as an enumeration. Barely any more boilerplate ...
sealed trait WeekDay
sealed abstract class WeekDay(val ordinal: Int) extends Serializable
object WeekDay {
val Mon, Tue, Wed, Thu, Fri, Sat, Sun = new WeekDay {}
private var ordinal = 0
val Mon, Tue, Wed, Thu, Fri, Sat, Sun =
try new WeekDay(ordinal) {}
finally ordinal += 1
val values: Set[WeekDay] = Values
}

Expand All @@ -68,7 +71,8 @@ object ShapelessEnumDemo extends App {
case _ => false // compile time non-exhaustive match warning/error without this case
}

assert(!isWeekend(Mon)) //
assert(!isWeekend(Mon))
assert(values.size == values.map(_.ordinal).size)
}

// Infrastructure for the above. Original version due to Travis Brown,
Expand Down