public IO <Either <string, ImmutableList <GameState> > > readData(File file) => IO.@return(() => file .readAllLines() .map(dataLines => dataLines.get(0).fold( () => $"Trump card not found", trumpStr => Card.parseSuite(trumpStr.ToCharArray()[0]).fold( () => $"Trump card couldn't be parsed!", trumpSuite => parseStates(dataLines.Skip(1), trumpSuite) ) ) ) .run() .fold(exception => exception.Message.left(), _ => _) );
static IO <Unit> mainIO(ImmutableList <string> args) { var file = new File(Path.GetFullPath(Path.Combine(Environment.CurrentDirectory, @"..\..\..\Data.txt"))); var dataReader = new DataReader(); var data = dataReader.readData(file); var correctAnswer = "1211112121221102212111211012111211111111211211112112111112111111121211111111202222011111011111112111"; return(printLn(correctAnswer).flatMap(_ => data .map(e => e.fold( err => err, states => resultsToString(states.Select(play).Select(wonTheGame)) )) .flatMap(result => printLn(result).andThen(printLn(result == correctAnswer ? "Correct" :"Incorrect")) ) )); }