Skip to content

Commit

Permalink
simplify bson handler
Browse files Browse the repository at this point in the history
  • Loading branch information
ornicar committed Jun 21, 2024
1 parent d4be5bf commit 0c4724c
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions modules/challenge/src/main/BSONHandlers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,14 @@ private object BSONHandlers:
import Challenge.*
import lila.game.BSONHandlers.given

given BSONHandler[ColorChoice] = BSONIntegerHandler.as[ColorChoice](
{
case 1 => ColorChoice.White
case 2 => ColorChoice.Black
case _ => ColorChoice.Random
},
{
case ColorChoice.White => 1
case ColorChoice.Black => 2
case ColorChoice.Random => 0
}
)
given BSONHandler[ColorChoice] =
val map = Map(
0 -> ColorChoice.Random,
1 -> ColorChoice.White,
2 -> ColorChoice.Black
)
valueMapHandler[Int, ColorChoice](map)(i => map.find(_._2 == i).so(_._1))

given BSON[TimeControl] with
import chess.Clock
def reads(r: Reader) =
Expand Down

0 comments on commit 0c4724c

Please sign in to comment.