Skip to content

Instantly share code, notes, and snippets.

@KOBA789
Created November 26, 2011 13:23
Show Gist options
  • Select an option

  • Save KOBA789/1395662 to your computer and use it in GitHub Desktop.

Select an option

Save KOBA789/1395662 to your computer and use it in GitHub Desktop.
きっとMonadic
var fs = require('fs');
function putStrLn (m) {
return function (cb) {
if (m) {
m(function (str) {
console.log(str);
cb();
});
} else {
console.log(str);
cb();
}
}
}
function wait(time) {
return function (m) {
return function (cb) {
if (m) {
m(function() {
setTimeout(function () {
cb();
}, time);
});
} else {
setTimeout(function () {
cb();
}, time);
}
}
}
}
function val (val) {
return function (m) {
return function (cb) {
if (m) {
m(function () {
cb(val);
});
} else {
cb(val);
}
}
}
}
function getClockTime (m) {
return function (cb) {
if (m) {
m(function () {
cb((new Date).toString());
});
} else {
cb((new Date).toString());
}
}
}
var noop = function () {};
var main =
putStrLn(
getClockTime(
putStrLn(
val('world')(
wait(1000)(
putStrLn(
getClockTime(
putStrLn(
val('hello')()
)
)
)
)
)
)
)
)
main(noop);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment