Message from JavaScript discussions

November 2017

— A HTTP server that increments a counter without modifying state


function count(i) {
server.once('request', function (req, res) {
return count(i + 1);


— Use on existing server to create a request counter

— The "pro" here is that it avoids mutating state
The con is that this STILL isn't a pure functional monadic interface

Message permanent page

— For two reasons:
.once is a side effect (mutates internal state of the event emitter)
res.end is not wrapped in a monadic type (like a promise)

Message permanent page

— Is once an actual js function

— I can't find the MDN reference

— No

— Part of nodejs

— But browsers have the equivalent I believe

— Give me a sec

— Well, almost