Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.