Skip to content

Instantly share code, notes, and snippets.

@rarous
Last active December 16, 2015 10:19
Show Gist options
  • Select an option

  • Save rarous/5419064 to your computer and use it in GitHub Desktop.

Select an option

Save rarous/5419064 to your computer and use it in GitHub Desktop.
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);
}
}
@rarous
Copy link
Copy Markdown
Author

rarous commented Apr 19, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment