by zsombor · 12y ago · 0 comments
credentials := NewCredentials(token)
User.findByName(credentials.userName)
The above is in Go, and it is just as fast if not more. Whilst all requests are on their own goroutines, the runtime will schedule them using the same efficient async io that does not need to be made visible as in JavaScript. var withThis = (object, f) => function bound() {
return f.apply(object, arguments);
}
function getCredentialsByToken(token) {
return newCredentials(token)
.then(withThis(User, User.findByName));
}When you're writing in functional style, you'd use arrows, which work nicely both for small lambdas and for writing combinators that can be partially applied. When you're writing in a more procedural style, generators are your "do syntax" equivalent(-ish):
async(function* getCredentialsByToken(token) {
credentials = yield NewCredentials(token)
return User.findByName(credentials.userName)
});
ES6 is a lot more powerful than it looks :)The difference between "functional" and "procedural" style here is nothing more than monadic bind operator vs do-notation, but what you have above or in the initial response is nothing like that.
Also I'm not sure "arrows" -- http://www.haskell.org/haskellwiki/Arrow -- means what you think it means in the context of functional programming? It's not sugar for `function(){}`...