/*
The file does not exist:
[ERROR LOG]: Could not find file 'D:\Foo.txt'.
The file exists but contains malformed JSON “{'X': '10','Y': '20'}, '{“
[ERROR LOG]: Additional text encountered after finished reading JSON content: ,. Path '', line 1, position 21.
The file exists and contains correctly formed JSON
QUAXX: (20, 40)
*/
Quaxx ProcessQuaxx(Quaxx quaxx) => new Quaxx(quaxx.X * 2, quaxx.Y * 2);
void Log(string error) => $"[ERROR LOG]: {error}".Dump();
void DisplayQuaxx(Quaxx quaxx) => $"QUAXX: ({quaxx.X}, {quaxx.Y})".Dump();
Try<string> Read(string fileName) => () => File.ReadAllText(fileName);
Try<Quaxx> DeserializeQuaxx(string s) => () => JsonConvert.DeserializeObject<Quaxx>(s);
const string quaxxFile = @"D:\Foo.txt";
Read(quaxxFile).Bind(DeserializeQuaxx)
.Run()
.Map(ProcessQuaxx)
.Match(exception: (error) => Log(error.Message),
success: DisplayQuaxx);
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.