Skip to content

Instantly share code, notes, and snippets.

@gordonbrander
Created July 16, 2015 22:04
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gordonbrander/4d5ff35df74f440315c1 to your computer and use it in GitHub Desktop.
Save gordonbrander/4d5ff35df74f440315c1 to your computer and use it in GitHub Desktop.
Finite state switcher
// Create a finite state switching function.
// Given a list of states, returns a function that will take a `prev` state
// and `next` state and will only advance state to `next` if it is one of
// the defined states.
const states = (...states) => (prev, next) =>
states.indexOf(next) !== -1 ? next : prev;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment