<commit_before>define(function(){
function Collection(data, filter, selector) {
    this._data = data;
    this._filter = filter;
    this._selector = selector;
}

Collection.prototype.toArray = function(){
    var result = [];
    this.forEach(function(item){
        result.push(item);
    });
    return result;
}

Collection.prototype.where = function(func){
    return new Collection(this, func);
}

Collection.prototype.select = function(func){
    return new Collection(this,null,func);
}

Collection.prototype.groupBy = function(func){
    var groupedCollection = new Collection(this);

    //override forEach method
    groupedCollection.forEach = function(fn){
        var groups = {};
        Collection.prototype.forEach.call(this,function(item){
            var key = func(item);
            var list = groups[key];
            if(list == null) {
                list = groups[key] = [];
            }
            list.push(item);
        });

        _forEach(groups,function(item,i){
            fn({key:i,value:item},i);
        });
    }

    return groupedCollection;
};

Collection.prototype.toMap = function(func){
    var mappedCollection = new Collection(this);
    mappedCollection.forEach = function(fn){
        var map = {};
        Collection.prototype.forEach.call(this, function(item){
            var key = func(item);
            map[key] = item;
        });

        _forEach(map,function(item,i){
            fn(item,i);
        });
    };
    return mappedCollection;
};

Collection.prototype.orderBy = function(func){

};

Collection.prototype.orderByDesc = function(func){

};

Collection.prototype.aggregate = function(func){

};

Collection.prototype.max = function(func){
    var max = {value : null };
    func = func || function(x){return x;}
    this.forEach(function(item){
        var x = func(item);
        if(max.value < x) {
            max.value = x;
        }
    });
    return max.value;
};

Collection.prototype.min = function(func){
    var min = {value : null };
    var count = 0;
    func = func || function(x){return x;}
    this.forEach(function(item){
        var x = func(item);
        if(count++ == 0){
            min.value = x;
        }
        if(min.value > x) {
            min.value = x;
        }
    });
    return min.value;
};

Collection.prototype.selectMany = function(func){
    var nestedCollection = new Collection(this);
    // override forEach
    nestedCollection.forEach = function(fn){
        Collection.prototype.forEach.call(this,function(item,i){
            _forEach(func(item),fn);
        });        
    }
    return nestedCollection;
};

Collection.prototype.forEach = function(fn){
    if(typeof(this._filter) == 'function') {
        return _forEach(this._data,(function(item){
            if(this._filter(item) == true){
                fn(item);
            }
        }).bind(this));
    }

    if(typeof(this._selector) == 'function'){<commit_msg>Collection 'where' filter function is passed item key<commit_after>define(function(){
function Collection(data, filter, selector) {
    this._data = data;
    this._filter = filter;
    this._selector = selector;
}

Collection.prototype.toArray = function(){
    var result = [];
    this.forEach(function(item){
        result.push(item);
    });
    return result;
}

Collection.prototype.where = function(func){
    return new Collection(this, func);
}

Collection.prototype.select = function(func){
    return new Collection(this,null,func);
}

Collection.prototype.groupBy = function(func){
    var groupedCollection = new Collection(this);

    //override forEach method
    groupedCollection.forEach = function(fn){
        var groups = {};
        Collection.prototype.forEach.call(this,function(item){
            var key = func(item);
            var list = groups[key];
            if(list == null) {
                list = groups[key] = [];
            }
            list.push(item);
        });

        _forEach(groups,function(item,i){
            fn({key:i,value:item},i);
        });
    }

    return groupedCollection;
};

Collection.prototype.toMap = function(func){
    var mappedCollection = new Collection(this);
    mappedCollection.forEach = function(fn){
        var map = {};
        Collection.prototype.forEach.call(this, function(item){
            var key = func(item);
            map[key] = item;
        });

        _forEach(map,function(item,i){
            fn(item,i);
        });
    };
    return mappedCollection;
};

Collection.prototype.orderBy = function(func){

};

Collection.prototype.orderByDesc = function(func){

};

Collection.prototype.aggregate = function(func){

};

Collection.prototype.max = function(func){
    var max = {value : null };
    func = func || function(x){return x;}
    this.forEach(function(item){
        var x = func(item);
        if(max.value < x) {
            max.value = x;
        }
    });
    return max.value;
};

Collection.prototype.min = function(func){
    var min = {value : null };
    var count = 0;
    func = func || function(x){return x;}
    this.forEach(function(item){
        var x = func(item);
        if(count++ == 0){
            min.value = x;
        }
        if(min.value > x) {
            min.value = x;
        }
    });
    return min.value;
};

Collection.prototype.selectMany = function(func){
    var nestedCollection = new Collection(this);
    // override forEach
    nestedCollection.forEach = function(fn){
        Collection.prototype.forEach.call(this,function(item,i){
            _forEach(func(item),fn);
        });        
    }
    return nestedCollection;
};

Collection.prototype.forEach = function(fn){
    if(typeof(this._filter) == 'function') {
        return _forEach(this._data,(function(item,key){
            if(this._filter(item,key) == true){
                fn(item,key);
            }
        }).bind(this));
    }

    if(typeof(this._selector) == 'function'){
{'fraction_non_alphanumeric': 0.14254459777852574, 'fraction_numerical': 0.0006731740154830024, 'mean_word_length': 2.3538374717832955, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '2091913', 'n_tokens_mistral': 1718, 'n_tokens_neox': 1695, 'n_words': 324}