4 ms·
Option types are the way to go for something like this: public static class Parse { public static Option<int> TryInt(string str) {
by louthy 10y ago
Option types are the way to go for something like this:
public static class Parse
{
public static Option<int> TryInt(string str)
{
int value;
return Int32.TryParse(str, out value)
? Some(value)
: None;
}
}
var x = Parse.Int("123").IfNone(0);
var x = Parse.Int("456").Match(
Some: x => x * 2,
None: () => 0
);
Parse.Int("456").Iter(Console.WriteLine);
https://github.com/louthy/language-ext/blob/e6ff382a1752c7de575629f43e4f20257a12d525/LanguageExt.Tests/TryOutTests.cs https://github.com/louthy/language-ext/blob/e6ff382a1752c7de...