Created
July 16, 2015 22:04
-
-
Save gordonbrander/4d5ff35df74f440315c1 to your computer and use it in GitHub Desktop.
Finite state switcher
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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