Skip to content

Instantly share code, notes, and snippets.

Avatar

MarcinNajder marcinnajder

View GitHub Profile
View HackingAsyncAwait_AnyMonadImpl.cs
async Optional<string> ProcessText(string text1, string text2)
{
int number1 = await TryParseInt(text1);
int number2 = await TryParseInt(text2);
return (number1 + number2).ToString();
}
Optional<int> TryParseInt(string text) =>
int.TryParse(text, out var result) ? new Optional<int>(result) : Optional<int>.None;
View HackingAsyncAwait_OptionalSpecificImpl.cs
async Optional<string> ProcessText(string text1, string text2)
{
int number1 = await TryParseInt(text1);
int number2 = await TryParseInt(text2);
return (number1 + number2).ToString();
}
Optional<int> TryParseInt(string text) =>
int.TryParse(text, out var result) ? new Optional<int>(result) : Optional<int>.None;