Last active
December 16, 2015 10:19
-
-
Save rarous/5419064 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 static class ParseEx { | |
| public delegate bool ParserDelegate<T>(string input, out T result); | |
| public static Maybe<T> Parse<T>(string input, ParserDelegate<T> parser) { | |
| T result; | |
| bool isSuccess = parser(input, out result); | |
| return isSuccess ? result.ToMaybe() : new Nothing<T>(); | |
| } | |
| public static Maybe<DateTime> ParseDateTime(string input) { | |
| return Parse<DateTime>(input, DateTime.TryParse); | |
| } | |
| public static Maybe<int> ParseInt32(string input) { | |
| return Parse<int>(input, Int32.TryParse); | |
| } | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Use with https://gist.github.com/rarous/5355792