Skip to content

Instantly share code, notes, and snippets.

@richlander
Created January 29, 2019 17:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save richlander/0a2d3276a449a487421ebdd27dd5d763 to your computer and use it in GitHub Desktop.
Save richlander/0a2d3276a449a487421ebdd27dd5d763 to your computer and use it in GitHub Desktop.
C# 8 Switch Expression Tuple Deconstruction and Positional Pattern
static State ChangeState(State current, Transition transition, bool hasKey) =>
(current, transition) switch
{
(Opened, Close) => Closed,
(Closed, Open) => Opened,
(Closed, Lock) when hasKey => Locked,
(Locked, Unlock) when hasKey => Closed,
_ => throw new InvalidOperationException($"Invalid transition")
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment