Skip to content

Instantly share code, notes, and snippets.

@olexale
Created August 2, 2017 19:21
Show Gist options
  • Save olexale/2cf6b592fd6af16430d3c0de2ed3d9f0 to your computer and use it in GitHub Desktop.
Save olexale/2cf6b592fd6af16430d3c0de2ed3d9f0 to your computer and use it in GitHub Desktop.
class CounterReducer
{
public CounterState Reduce(CounterState state, object action)
{
switch (action)
{
case IncrementAction i:
return ProcessIncrement(state);
case DecrementAction d:
return ProcessDecrement(state);
default:
throw new ArgumentException("action is not supported");
}
}
private CounterState ProcessIncrement(CounterState state)
{
return new CounterState(state.Count + 1);
}
private CounterState ProcessDecrement(CounterState state)
{
return new CounterState(state.Count - 1);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment