Shorten day2 a bit more with .into

This commit is contained in:
Natsu Kagami 2023-12-03 17:15:52 +01:00
parent 2c98de01f8
commit b79159a41f
Signed by: nki
GPG key ID: 55A032EB38B49ADB

View file

@ -12,11 +12,10 @@ case class Game(id: Int, hands: List[Hand]):
object Parser extends CommonParser:
val update =
num ~ (
"red" ^^ (_ => (num: Int) => (h: Hand) => h.copy(red = num)) |
"green" ^^ (_ => (num: Int) => (h: Hand) => h.copy(green = num)) |
"blue" ^^ (_ => (num: Int) => (h: Hand) => h.copy(blue = num))
) ^^ { case (num ~ f) => f(num) }
num.into: num =>
"red" ^^^ ((h: Hand) => h.copy(red = num)) |
"green" ^^^ ((h: Hand) => h.copy(green = num)) |
"blue" ^^^ ((h: Hand) => h.copy(blue = num))
val hand = rep1sep(update, ",").map(_.foldRight(Hand(0, 0, 0))(_(_)))
val game = "Game" ~ num ~ ":" ~ repsep(hand, ";") ^^ {