Monads/Writer monad: Difference between revisions

Content added Content deleted
(J draft)
Line 94: Line 94:


log_half = loggingVersion(half, "divided by 2");
log_half = loggingVersion(half, "divided by 2");





Line 131: Line 130:
// and then nests function applications (working from right to left)
// and then nests function applications (working from right to left)
function logCompose(lstFunctions, value) {
function logCompose(lstFunctions, value) {
return lstFunctions
return lstFunctions.reduceRight(
.reduceRight(function (writerA, f) {
writerBind,
return writerBind(writerA, f);
writerUnit(value)
}, writerUnit(value));
);
}
}