lib/index.js
function firstOf(items, evaluate) {
  return new Promise((accept, reject) => {
    (function next(i) {
      if (i >= items.length) {
        accept(null);
        return;
      }

      setImmediate(() => evaluate(items[i], (err, value) => {
        if (err) reject(err);
        else if (value) accept(value);
        else next(i + 1);
      }));
    })(0);
  });
}
function firstOf(items, evaluate) {
  return new Promise((accept, reject) => {
    (function next(i) {
      if (i >= items.length) {
        accept(null);
        return;
      }

      setImmediate(() => evaluate(items[i], (err, value) => {
        if (err) reject(err);
        else if (value) accept(value);
        else next(i + 1);
      }));
    })(0);
  });
}
function firstOf ( items , evaluate ) { return new Promise ( ( accept , reject ) => { ( function next ( i ) { if ( i >= items . length ) { accept ( null ) ; return ; } setImmediate ( ( ) => evaluate ( items [ i ] , ( err , value ) => { if ( err ) reject ( err ) ; else if ( value ) accept ( value ) ; else next ( i + 1 ) ; } ) ) ; } ) ( 0 ) ; } ) ; }
Call the evaluate function asynchronously on each item in the items array,
and return a promise that will fail on the first error evaluate produces, or
resolve to the first truthy value which evaluate produces. If all items
evaluate to falsy values, and evaluate never produces an error, the promise
will resolve to null.

@param {Array<*>} items An array of opaque items.
@param {Function(*, Function(?Error=, *=))} evaluate
@return {Promise<*>}
Call the evaluate function asynchronously on each item in the items array and return a promise that will fail on the first error evaluate produces or resolve to the first truthy value which evaluate produces . If all items evaluate to falsy values and evaluate never produces an error the promise will resolve to null .