Skip to content

Instantly share code, notes, and snippets.

@o0
Created November 23, 2016 02:45
Show Gist options
  • Save o0/d517fbedd73ee759cb3beaf7574bd048 to your computer and use it in GitHub Desktop.
Save o0/d517fbedd73ee759cb3beaf7574bd048 to your computer and use it in GitHub Desktop.
Either monad countdown timer. Requires monet.js
'use strict';
const tick = level => level.time === 1 ?
Left(`Time's up`) :
Right(Object.assign({}, level, { time: level.time - 1 }));
const countdown = (level) => {
console.info(level.time);
setTimeout(() => tick(level).cata(console.error, countdown), 1000);
};
countdown({ time: 30 });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment