Skip to content

Instantly share code, notes, and snippets.

@laduke
Created February 19, 2018 17:59
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 laduke/43304e6f0da4024064c967f18a23bf28 to your computer and use it in GitHub Desktop.
Save laduke/43304e6f0da4024064c967f18a23bf28 to your computer and use it in GitHub Desktop.
var daggy = require('daggy')
const Machine = daggy.taggedSum('Timer', {
Yellow: [],
Green: [],
Red: []
})
Machine.prototype.timer =
function () {
return this.cata({
Green: () => Machine.Yellow,
Yellow: () => Machine.Red,
Red: () => Machine.Green,
})
}
var machine = Machine.Red
console.log(machine.toString())
machine = machine.timer()
console.log(machine.toString())
machine = machine.timer()
console.log(machine.toString())
machine = machine.timer()
console.log(machine.toString())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment