Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bluebird .then method

The Bluebird docs for the .call method have a code sample labeled, "Chaining lo-dash or underscore methods".

What is the purpose of the chained .then(_) in the code snippet below?

var Promise = require("bluebird");

...

var _ = require("lodash");
var fs = Promise.promisifyAll(require("fs"));

fs.readdirAsync(".").then(_) <-- ???
    .call("groupBy", function(fileName) {
        return fileName.charAt(0);
    })

...

Thanks!

like image 420
James Sun Avatar asked Dec 19 '25 19:12

James Sun


1 Answers

In underscore the _ identifier is a function as well as a namespace.

Doing .then returns the result of the passed function.

Calling the _ function starts a underscore chain, any consecutive actions happen on the object passed. It starts a chain with the result of readdirAsync.

like image 137
Benjamin Gruenbaum Avatar answered Dec 21 '25 20:12

Benjamin Gruenbaum



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!