Skip to content

Instantly share code, notes, and snippets.

@dimitris-papadimitriou-chr
Created July 21, 2020 18:03
Show Gist options
  • Save dimitris-papadimitriou-chr/6b1d1b6d3a88f49d9cc1ba1cd6722397 to your computer and use it in GitHub Desktop.
Save dimitris-papadimitriou-chr/6b1d1b6d3a88f49d9cc1ba1cd6722397 to your computer and use it in GitHub Desktop.
public static partial class FunctionalExt
{
public static Tree<T> Reverse<T>(this Tree<T> @this) =>
@this switch
{
Leaf<T> { Value: var v } => new Leaf<T>(v),
Node<T> { Left: var l, Value: var v, Right: var r } =>
new Node<T>(r.Reverse(), v, l.Reverse()),
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment