Created
February 19, 2018 17:59
-
-
Save laduke/43304e6f0da4024064c967f18a23bf28 to your computer and use it in GitHub Desktop.
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
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