What is the functional programming equivalent of the decorator design pattern?
For example, how would you write this particular example in a functional style?
Here's an example using JSGI, a web server API for JavaScript:
function Log(app) {
return function(request) {
var response = app(request);
console.log(request.headers.host, request.path, response.status);
return response;
};
}
var app = Logger(function(request) {
return {
status: 200,
headers: { "Content-Type": "text/plain" },
body: ["hello world"]
};
}
Compliant middleware can be stacked, of course (e.x. Lint(Logger(ContentLength(app)))
)