Skip to content

Instantly share code, notes, and snippets.

@GHvW

GHvW/heresy.cs Secret

Created April 6, 2019 13:26
Show Gist options
  • Save GHvW/b5a093ad28c745a7516bcc9916fc2ea4 to your computer and use it in GitHub Desktop.
Save GHvW/b5a093ad28c745a7516bcc9916fc2ea4 to your computer and use it in GitHub Desktop.
heresy in C#
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