-
-
Save GHvW/b5a093ad28c745a7516bcc9916fc2ea4 to your computer and use it in GitHub Desktop.
heresy in C#
This file contains 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
namespace Heresy { | |
public static class NullableReferenceExtensions { | |
public static U? Map<T, U>(this T? x, Func<T, U> fn) | |
where T : class | |
where U : class { | |
return x switch { | |
null => null, | |
T it => fn(it) | |
}; | |
} | |
public static U? FlatMap<T, U>(this T? x, Func<T, U?> fn) | |
where T : class | |
where U : class { | |
return x switch { | |
null => null, | |
T it => fn(it) | |
}; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment