Re:New Features in C# 7.0
by canadaj on Thursday March 09, 2017 @07:35PM
(#13835273)
I see your point on out parameters, they are ripe for abuse. You can abuse out parameters right now, just with a little more effort.
Where this becomes useful, I think, are places where you can't avoid using an out parameter. Now, you can choose to throw away or use the out parameter without explicitly declaring it.
[ Parent
| on HN ]
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/e6ff382a1752c7de...