• Jump To … +
    all.js any.js anything.js array.js filter.js find.js index.js map.js pull.js range.js reduce.js reject.js s-pipe.js split.js
  • find.js

  • ¶
    var PullStream = require('./pull');
  • ¶

    The FindStream class will emit the first chunk that matches a predicate, closing the source stream when it does

    var FindStream = PullStream.extend({
      constructor: function FindStream(source, cb) {
        PullStream.call(this, source);
        this._cb = cb;
      },
    
      _process: function(chunk) {
        if (this._cb(chunk)) {
          this._forward(chunk);
          this.pause();
          this.close();
        }
      }
    });
    
    
    module.exports = function find(cb) {
      return new FindStream(this, cb);
    };