Skip to content

Instantly share code, notes, and snippets.

@SimonRichardson
Created September 12, 2013 10:23
Show Gist options
  • Select an option

  • Save SimonRichardson/6535450 to your computer and use it in GitHub Desktop.

Select an option

Save SimonRichardson/6535450 to your computer and use it in GitHub Desktop.
Time structure
var time = function(milliseconds) {
var value = milliseconds;
return {
concat: function(t) {
return time(value + t.extract());
},
extract: function() {
return value;
},
map: function(f) {
return time(f(value));
}
}
}
function asSeconds(value) {
return value / 1000;
}
function asMinutes(value) {
return value / 1000 / 60;
}
// Implementation
var second = time(1000);
var minute = time(60000);
var minutes30 = minute.map(function(value) {
return value * 30;
});
var seconds2 = second.concat(second);
seconds2.map(asSeconds).map(function(value) {
console.log(value);
});
minutes30.map(asMinutes).map(function(value) {
console.log(value);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment