title: Can you avoid nesting altogether with Promises?
body: <p>From what I understand one of the main selling points for Promises is the ability to write flat code (or, flatter than callback hell).</p>
  
  <p>Though it seems that in many cases we need to nest promises, in order to use closure. For example (from <a href="https://www.npmjs.org/package/q" rel="noreferrer">q</a>'s docs, though I use Bluebird):</p>
  
  <pre><code>function authenticate() {
      return getUsername()
          .then(function (username) {
              return getUser(username);
          })
          // chained because we will not need the user name in the next event
          .then(function (user) {
              return getPassword()
                  // nested because we need both user and password next
                  .then(function (password) {
                      if (user.passwordHash !== hash(password)) {
                          throw new Error("Can't authenticate");
                      }
                  });
          });
  }
  </code></pre>
  
  <p>Is there a cleaner way to do this, without nesting? </p>
  
  <p>EDIT: I've managed to clean up this specific example using <code>.all</code>, but there are more complex cases where I don't think it can be done:</p>
  
  <pre><code>function authenticate() {
      return Promise.all([
          getUsername().then(getUser),
          getPassword()
      ]).spread(function (user, password) {
          if (user.passwordHash !== hash(password)) {
              throw new Error('Can\'t authenticate');
          }
      });
  }
  </code></pre>