Skip to content

Instantly share code, notes, and snippets.

@dimitris-papadimitriou-chr
Created July 10, 2020 18:00
Show Gist options
  • Select an option

  • Save dimitris-papadimitriou-chr/0b52466ffb50164b3a2b5d06e111aebe to your computer and use it in GitHub Desktop.

Select an option

Save dimitris-papadimitriou-chr/0b52466ffb50164b3a2b5d06e111aebe to your computer and use it in GitHub Desktop.
int? shape = null;
Shape shape = null;
Shape shape = new Rectangle
{
Width = 100,
Height = 100,
};
//this is valid for all the above
var t = shape.Map(x => x.ToString());
public static class FunctionalExt
{
public static T1 Map<T, T1>(this T @this, Func<T, T1> f) =>
@this switch
{
T value => f(value),
null => default,
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment