From 37c7630a6cfd289290829b0b4ac84953bec3b382 Mon Sep 17 00:00:00 2001 From: Thanh Le Date: Tue, 10 Oct 2023 20:03:25 +0200 Subject: [PATCH] Remove head.option --- src/main/scala/Replay.scala | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/main/scala/Replay.scala b/src/main/scala/Replay.scala index 29386a139..14387e3ca 100644 --- a/src/main/scala/Replay.scala +++ b/src/main/scala/Replay.scala @@ -54,16 +54,17 @@ object Replay: val init = makeGame(variant, initialFen.some) val emptyGames = List.empty[(Game, Uci.WithSan)] sans - .foldM(emptyGames): - case (games, str) => + .foldM((init, emptyGames)): + case ((head, games), str) => Parser .sanOnly(str) .flatMap: san => - val game = games.headOption.fold(init)(_._1) - san(game.situation) - .map(m => (m.applyGame(game), Uci.WithSan(m.toUci, str)) :: games) + san(head.situation) + .map: move => + val newGame = move.applyGame(head) + (newGame, (newGame, Uci.WithSan(move.toUci, str)) :: games) .leftMap(err => (init, games.reverse, err.some)) - .map(gs => (init, gs.reverse, none)) + .map(gs => (init, gs._2.reverse, none)) .merge private def computeSituations[M](