Created
September 12, 2013 10:23
-
-
Save SimonRichardson/6535450 to your computer and use it in GitHub Desktop.
Time structure
This file contains hidden or 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 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