From b79159a41fb0edf4a29c72ec118fe3df90e6a994 Mon Sep 17 00:00:00 2001 From: Natsu Kagami Date: Sun, 3 Dec 2023 17:15:52 +0100 Subject: [PATCH] Shorten day2 a bit more with .into --- Day2.scala | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/Day2.scala b/Day2.scala index 9b773ba..d552c91 100644 --- a/Day2.scala +++ b/Day2.scala @@ -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, ";") ^^ {