Created
December 18, 2019 15:48
-
-
Save ythirion/fac16557b5254fecb407265c6359229b to your computer and use it in GitHub Desktop.
Try
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void file_monad_example() | |
{ | |
GetLine() | |
.Bind(ReadFile) | |
.Bind(PrintStrln) | |
.Match(success => Console.WriteLine("SUCCESS"), | |
failure => Console.WriteLine("FAILURE")); | |
} | |
static Try<string> GetLine() | |
{ | |
Console.Write("File:"); | |
return Try(() => Console.ReadLine()); | |
} | |
static Try<string> ReadFile(string filePath) => Try(() => File.ReadAllText(filePath)); | |
static Try<bool> PrintStrln(string line) | |
{ | |
Console.WriteLine(line); | |
return Try(true); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment