Shorten day2 a bit more with .into
This commit is contained in:
parent
2c98de01f8
commit
b79159a41f
|
@ -12,11 +12,10 @@ case class Game(id: Int, hands: List[Hand]):
|
||||||
|
|
||||||
object Parser extends CommonParser:
|
object Parser extends CommonParser:
|
||||||
val update =
|
val update =
|
||||||
num ~ (
|
num.into: num =>
|
||||||
"red" ^^ (_ => (num: Int) => (h: Hand) => h.copy(red = num)) |
|
"red" ^^^ ((h: Hand) => h.copy(red = num)) |
|
||||||
"green" ^^ (_ => (num: Int) => (h: Hand) => h.copy(green = num)) |
|
"green" ^^^ ((h: Hand) => h.copy(green = num)) |
|
||||||
"blue" ^^ (_ => (num: Int) => (h: Hand) => h.copy(blue = num))
|
"blue" ^^^ ((h: Hand) => h.copy(blue = num))
|
||||||
) ^^ { case (num ~ f) => f(num) }
|
|
||||||
val hand = rep1sep(update, ",").map(_.foldRight(Hand(0, 0, 0))(_(_)))
|
val hand = rep1sep(update, ",").map(_.foldRight(Hand(0, 0, 0))(_(_)))
|
||||||
|
|
||||||
val game = "Game" ~ num ~ ":" ~ repsep(hand, ";") ^^ {
|
val game = "Game" ~ num ~ ":" ~ repsep(hand, ";") ^^ {
|
||||||
|
|
Loading…
Reference in a new issue