<commit_before>Asyncplify.prototype.catch = function(options) {
    return new Asyncplify(Catch, options, this);
};

function Catch(options, sink, source) {
    this._i = 0;
    this._sink = sink;
    this._source = null;
    this._sources = null;
    if(options && options._mapper) this._mapper = options._mapper;
    else if(typeof options === 'function') this._mapper = options;
    else this._sources = options && options.sources || Array.isArray(options) ? options : [];
    sink._source = this;
    source._subscribe(this);
}
Catch.prototype = {
    cancel: function() {
        this._sink = null;
        if(this._source) this._source.cancel();
    },
    emit: function(value) {
        if(this._sink) this._sink.emit(value);
    },
    end: function(err) {
        this._source = null;
        if(err && this.sink) {
            var source = this._mapper(err, this._sink);
            if(source && this._sink) return source._subscribe(this);
        }
        if(this._sink) {
            this._sink.end(null);
            this._sink = null;
        }
    },
    _mapper: function() {
        return this._i < this._sources.length && this._sources[this._i++];
    }
};<commit_msg>refactoring / simplification of catch operator<commit_after>Asyncplify.prototype.catch = function(options) {
    return new Asyncplify(Catch, options, this);
};

function Catch(options, sink, source) {
    this.i = 0;
    this.sink = sink;
    this.source = null;
    this.sources = null;
    
    if (typeof options === 'function')
        this.mapper = options;
    else
        this.sources = Array.isArray(options) ? options [];
    
    sink.source = this;
    source._subscribe(this);
}
        
Catch.prototype = {
    close: function() {
        this.sink = null;
        
        if (this.source)
            this.source.close();
    },
    emit: function(value) {
        if (this.sink)
            this.sink.emit(value);
    },
    end: function(err) {
        this.source = null;
        
        if (err && this.sink) {
            var source = this.mapper(err);
            
            if (source && this.sink)
                return source._subscribe(this);
        }
        
        if (this.sink) {
            this.sink.end(null);
            this.sink = null;
        }
    },
    mapper: function() {
        return this.i < this.sources.length && this.sources[this.i++];
    }
};
{'fraction_non_alphanumeric': 0.13885403596821413, 'fraction_numerical': 0.000836470096194061, 'mean_word_length': 1.9974937343358397, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2072499', 'n_tokens_mistral': 747, 'n_tokens_neox': 743, 'n_words': 148}