ts-generic-collections-linq
Version:
TypeScript library provides strongly-typed, queryable collections.
1,609 lines (1,605 loc) • 82.9 kB
JavaScript
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
typeof define === 'function' && define.amd ? define('ts-generic-collections-linq', ['exports'], factory) :
(factory((global['ts-generic-collections-linq'] = {})));
}(this, (function (exports) { 'use strict';
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/**
* @template T
*/
var /**
* @template T
*/ List = /** @class */ (function () {
function List(array) {
if (array === void 0) {
array = null;
}
this.list = new Array();
if (array)
this.list = array;
}
/* IList */
/* IList */
/**
* @param {?} item
* @return {?}
*/
List.prototype.add = /* IList */
/**
* @param {?} item
* @return {?}
*/
function (item) {
this.list.push(item);
};
/**
* @param {?} items
* @return {?}
*/
List.prototype.addRange = /**
* @param {?} items
* @return {?}
*/
function (items) {
var _this = this;
items.forEach(( /**
* @param {?} x
* @return {?}
*/function (x) { return _this.add(x); }));
};
/**
* @param {?} predicate
* @return {?}
*/
List.prototype.remove = /**
* @param {?} predicate
* @return {?}
*/
function (predicate) {
/** @type {?} */
var temp = new Array();
this.list.forEach(( /**
* @param {?} element
* @return {?}
*/function (element) {
if (!predicate(element)) {
temp.push(element);
}
}));
this.list = temp;
};
/**
* @param {?} index
* @return {?}
*/
List.prototype.removeAt = /**
* @param {?} index
* @return {?}
*/
function (index) {
this.list.splice(index, 1);
};
/**
* @return {?}
*/
List.prototype.clear = /**
* @return {?}
*/
function () {
this.list = new Array();
};
/* IEnumerable */
/* IEnumerable */
/**
* @return {?}
*/
List.prototype.asEnumerable = /* IEnumerable */
/**
* @return {?}
*/
function () {
return this;
};
Object.defineProperty(List.prototype, "length", {
get: /**
* @return {?}
*/ function () {
return this.list.length;
},
enumerable: true,
configurable: true
});
/**
* @param {?} index
* @return {?}
*/
List.prototype.elementAt = /**
* @param {?} index
* @return {?}
*/
function (index) {
try {
return this.list[index];
}
catch (e) {
return null;
}
};
/**
* @param {?=} predicate
* @return {?}
*/
List.prototype.any = /**
* @param {?=} predicate
* @return {?}
*/
function (predicate) {
if (!predicate) {
return this.list.length > 0;
}
for (var i = 0; i < this.list.length; i++) {
if (predicate(this.list[i])) {
return true;
}
}
return false;
};
/**
* @param {?=} predicate
* @return {?}
*/
List.prototype.all = /**
* @param {?=} predicate
* @return {?}
*/
function (predicate) {
if (!predicate) {
return this.list.length > 0;
}
for (var i = 0; i < this.list.length; i++) {
if (!predicate(this.list[i])) {
return false;
}
}
return true;
};
/**
* @param {?=} predicate
* @return {?}
*/
List.prototype.single = /**
* @param {?=} predicate
* @return {?}
*/
function (predicate) {
if (predicate === void 0) {
predicate = null;
}
if (this.list.length <= 0) {
throw ITEM_NOT_FOUND_MSG;
}
if (predicate) {
/** @type {?} */
var item = this.singleOrDefault(predicate);
if (!item) {
throw ITEM_NOT_FOUND_MSG;
}
return item;
}
return this.list[0];
};
/**
* @param {?=} predicate
* @return {?}
*/
List.prototype.first = /**
* @param {?=} predicate
* @return {?}
*/
function (predicate) {
if (predicate === void 0) {
predicate = null;
}
if (this.list.length <= 0) {
throw ITEM_NOT_FOUND_MSG;
}
if (predicate) {
/** @type {?} */
var item = this.firstOrDefault(predicate);
if (!item) {
throw ITEM_NOT_FOUND_MSG;
}
return item;
}
return this.list[0];
};
/**
* @param {?=} predicate
* @return {?}
*/
List.prototype.last = /**
* @param {?=} predicate
* @return {?}
*/
function (predicate) {
if (predicate === void 0) {
predicate = null;
}
if (this.list.length <= 0) {
throw ITEM_NOT_FOUND_MSG;
}
if (predicate) {
/** @type {?} */
var item = this.lastOrDefault(predicate);
if (!item) {
throw ITEM_NOT_FOUND_MSG;
}
return item;
}
return this.list[this.list.length - 1];
};
/**
* @param {?} predicate
* @return {?}
*/
List.prototype.singleOrDefault = /**
* @param {?} predicate
* @return {?}
*/
function (predicate) {
/** @type {?} */
var temp = new Array();
this.list.filter(( /**
* @param {?} element
* @return {?}
*/function (element) {
if (predicate(element)) {
temp.push(element);
}
}));
if (temp.length > 1) {
throw MULTIPLE_INSTANCES_FOUND_MSG;
}
if (temp.length <= 0) {
return null;
}
return temp[0];
};
/**
* @param {?} predicate
* @return {?}
*/
List.prototype.firstOrDefault = /**
* @param {?} predicate
* @return {?}
*/
function (predicate) {
for (var i = 0; i < this.length; i++) {
/** @type {?} */
var item = this.list[i];
if (predicate(item)) {
return item;
}
}
return null;
};
/**
* @param {?} predicate
* @return {?}
*/
List.prototype.lastOrDefault = /**
* @param {?} predicate
* @return {?}
*/
function (predicate) {
for (var i = this.length; i >= 0; i--) {
/** @type {?} */
var item = this.list[i - 1];
if (predicate(item)) {
return item;
}
}
return null;
};
/**
* @param {?} predicate
* @return {?}
*/
List.prototype.where = /**
* @param {?} predicate
* @return {?}
*/
function (predicate) {
/** @type {?} */
var temp = new List();
this.list.filter(( /**
* @param {?} element
* @return {?}
*/function (element) {
if (predicate(element)) {
temp.add(element);
}
}));
return temp;
};
/**
* @template TResult
* @param {?} predicate
* @return {?}
*/
List.prototype.select = /**
* @template TResult
* @param {?} predicate
* @return {?}
*/
function (predicate) {
/** @type {?} */
var temp = new List();
this.forEach(( /**
* @param {?} x
* @return {?}
*/function (x) { return temp.add(predicate(x)); }));
return temp;
};
/**
* @param {?} predicate
* @return {?}
*/
List.prototype.forEach = /**
* @param {?} predicate
* @return {?}
*/
function (predicate) {
this.list.forEach(( /**
* @param {?} x
* @return {?}
*/function (x) { return predicate(x); }));
};
/**
* @return {?}
*/
List.prototype.toArray = /**
* @return {?}
*/
function () {
return this.list.slice();
};
/**
* @template TOuter, TMatch, TResult
* @param {?} outer
* @param {?} conditionInner
* @param {?} conditionOuter
* @param {?} select
* @param {?=} leftJoin
* @return {?}
*/
List.prototype.join = /**
* @template TOuter, TMatch, TResult
* @param {?} outer
* @param {?} conditionInner
* @param {?} conditionOuter
* @param {?} select
* @param {?=} leftJoin
* @return {?}
*/
function (outer, conditionInner, conditionOuter, select, leftJoin) {
if (leftJoin === void 0) {
leftJoin = false;
}
/** @type {?} */
var resultList = new List();
this.list.forEach(( /**
* @param {?} x
* @return {?}
*/function (x) {
/** @type {?} */
var outerEntries = outer.toArray().filter(( /**
* @param {?} y
* @return {?}
*/function (y) { return conditionInner(x) === conditionOuter(y); }));
if (leftJoin && outerEntries && outerEntries.length <= 0) {
resultList.add(select(x, null));
}
else {
outerEntries.forEach(( /**
* @param {?} z
* @return {?}
*/function (z) { return resultList.add(select(x, z)); }));
}
}));
return resultList;
};
/**
* @param {?} predicate
* @return {?}
*/
List.prototype.groupBy = /**
* @param {?} predicate
* @return {?}
*/
function (predicate) {
/** @type {?} */
var groups = {};
this.list.forEach(( /**
* @param {?} o
* @return {?}
*/function (o) {
/** @type {?} */
var group = JSON.stringify(predicate(o));
groups[group] = groups[group] || [];
groups[group].push(o);
}));
/** @type {?} */
var g = Object.keys(groups).map(( /**
* @param {?} group
* @return {?}
*/function (group) {
/** @type {?} */
var a = group.substr(1, group.length - 2);
/** @type {?} */
var grp = new Group(new List(a.split(',')).select(( /**
* @param {?} x
* @return {?}
*/function (x) { return x.replace(/^(")?(.*?)(")?$/ig, "$2"); })).toArray(), groups[group]);
return grp;
}));
return new List(g);
};
/**
* @template TResult
* @param {?} predicate
* @return {?}
*/
List.prototype.selectMany = /**
* @template TResult
* @param {?} predicate
* @return {?}
*/
function (predicate) {
return this.list.reduce(( /**
* @param {?} out
* @param {?} inx
* @return {?}
*/function (out, inx) {
/** @type {?} */
var items = predicate(inx);
out.addRange(items);
return out;
}), new List(new Array()));
};
/**
* @param {?} comparer
* @return {?}
*/
List.prototype.orderBy = /**
* @param {?} comparer
* @return {?}
*/
function (comparer) {
/** @type {?} */
var temp = this.list.sort(( /**
* @param {?} x
* @param {?} y
* @return {?}
*/function (x, y) { return comparer.compare(x, y); }));
return new List(temp);
};
/**
* @param {?} list
* @return {?}
*/
List.prototype.union = /**
* @param {?} list
* @return {?}
*/
function (list) {
this.addRange(list.toArray());
return this;
};
/**
* @return {?}
*/
List.prototype.reverse = /**
* @return {?}
*/
function () {
return new List(this.list.slice().reverse());
};
/**
* @param {?} comparer
* @return {?}
*/
List.prototype.distinct = /**
* @param {?} comparer
* @return {?}
*/
function (comparer) {
/** @type {?} */
var uniques = new List();
this.forEach(( /**
* @param {?} x
* @return {?}
*/function (x) {
if (uniques.length > 0) {
if (!uniques.any(( /**
* @param {?} y
* @return {?}
*/function (y) { return comparer.equals(x, y); }))) {
uniques.add(x);
}
}
else {
uniques.add(x);
}
}));
return uniques;
};
/**
* @param {?} no
* @return {?}
*/
List.prototype.skip = /**
* @param {?} no
* @return {?}
*/
function (no) {
if (no > 0) {
return new List(this.list.slice(no, this.list.length - 1));
}
return this;
};
/**
* @param {?} no
* @return {?}
*/
List.prototype.take = /**
* @param {?} no
* @return {?}
*/
function (no) {
if (no > 0) {
return new List(this.list.slice(0, no));
}
return this;
};
/**
* @param {?} predicate
* @return {?}
*/
List.prototype.sum = /**
* @param {?} predicate
* @return {?}
*/
function (predicate) {
/** @type {?} */
var sum = 0;
this.list.forEach(( /**
* @param {?} x
* @return {?}
*/function (x) { return sum = sum + predicate(x); }));
return sum;
};
/**
* @param {?} predicate
* @return {?}
*/
List.prototype.avg = /**
* @param {?} predicate
* @return {?}
*/
function (predicate) {
return this.sum(predicate) / this.length;
};
/**
* @param {?} predicate
* @return {?}
*/
List.prototype.min = /**
* @param {?} predicate
* @return {?}
*/
function (predicate) {
/** @type {?} */
var min = 0;
/** @type {?} */
var i = 0;
this.list.forEach(( /**
* @param {?} x
* @return {?}
*/function (x) {
if (i == 0) {
min = predicate(x);
}
else {
/** @type {?} */
var val = predicate(x);
if (val < min) {
min = val;
}
}
i++;
}));
return min;
};
/**
* @param {?} predicate
* @return {?}
*/
List.prototype.max = /**
* @param {?} predicate
* @return {?}
*/
function (predicate) {
/** @type {?} */
var max = 0;
/** @type {?} */
var i = 0;
this.list.forEach(( /**
* @param {?} x
* @return {?}
*/function (x) {
if (i == 0) {
max = predicate(x);
}
else {
/** @type {?} */
var val = predicate(x);
if (val > max) {
max = val;
}
}
i++;
}));
return max;
};
/**
* @param {?=} predicate
* @return {?}
*/
List.prototype.count = /**
* @param {?=} predicate
* @return {?}
*/
function (predicate) {
if (predicate === void 0) {
predicate = null;
}
if (!predicate) {
return this.length;
}
/** @type {?} */
var count = 0;
this.list.forEach(( /**
* @param {?} x
* @return {?}
*/function (x) {
if (predicate(x)) {
count++;
}
}));
return count;
};
return List;
}());
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/**
* @template T
*/
var /**
* @template T
*/ Group = /** @class */ (function () {
function Group(groups, list) {
this.list = new List();
this.groups = groups;
this.list = new List(list);
}
return Group;
}());
/** @type {?} */
var objCompare = ( /**
* @param {?} obj1
* @param {?} obj2
* @return {?}
*/function (obj1, obj2) {
if ((typeof obj1 !== 'object' && typeof obj1 !== 'function') && (typeof obj2 !== 'object' && typeof obj2 !== 'function')) {
return obj1 === obj2;
}
//Loop through properties in object 1
for (var p in obj1) {
//Check property exists on both objects
if (obj1.hasOwnProperty(p) !== obj2.hasOwnProperty(p))
return false;
switch (typeof (obj1[p])) {
//Deep compare objects
case 'object':
if (!objCompare(obj1[p], obj2[p]))
return false;
break;
//Compare function code
case 'function':
if (typeof (obj2[p]) == 'undefined' || (p != 'compare' && obj1[p].toString() != obj2[p].toString()))
return false;
break;
//Compare values
default:
if (obj1[p] != obj2[p])
return false;
}
}
//Check object 2 for any extra properties
for (var p in obj2) {
if (typeof (obj1[p]) == 'undefined')
return false;
}
return true;
});
/** @type {?} */
var ITEM_NOT_FOUND_MSG = "Item does not exist.";
/** @type {?} */
var MULTIPLE_INSTANCES_FOUND_MSG = "Multiple instances of entity found.";
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/**
* @template TKey, TValue
*/
var /**
* @template TKey, TValue
*/ Dictionary = /** @class */ (function () {
function Dictionary(list) {
if (list === void 0) {
list = null;
}
this.list = new Array();
if (list) {
this.list = list;
}
}
/* IList */
/* IList */
/**
* @param {?} key
* @param {?} value
* @return {?}
*/
Dictionary.prototype.add = /* IList */
/**
* @param {?} key
* @param {?} value
* @return {?}
*/
function (key, value) {
/** @type {?} */
var pair = new KeyValuePair(key, value);
if (this.containsKey(key)) {
throw "Duplicate key. Cannot add.";
}
this.list.push(pair);
};
/**
* @param {?} items
* @return {?}
*/
Dictionary.prototype.addRange = /**
* @param {?} items
* @return {?}
*/
function (items) {
var _this = this;
items.forEach(( /**
* @param {?} x
* @return {?}
*/function (x) { return _this.add(x.key, x.value); }));
};
/**
* @param {?} index
* @return {?}
*/
Dictionary.prototype.removeAt = /**
* @param {?} index
* @return {?}
*/
function (index) {
this.list.splice(index, 1);
};
/**
* @return {?}
*/
Dictionary.prototype.clear = /**
* @return {?}
*/
function () {
this.list = new Array();
};
/**
* @param {?} predicate
* @return {?}
*/
Dictionary.prototype.remove = /**
* @param {?} predicate
* @return {?}
*/
function (predicate) {
/** @type {?} */
var temp = new Array();
this.list.forEach(( /**
* @param {?} element
* @return {?}
*/function (element) {
if (!predicate(element)) {
temp.push(element);
}
}));
this.list = temp;
};
/**
* @param {?} key
* @return {?}
*/
Dictionary.prototype.containsKey = /**
* @param {?} key
* @return {?}
*/
function (key) {
return this.any(( /**
* @param {?} x
* @return {?}
*/function (x) { return objCompare(x.key, key); }));
};
/**
* @param {?} value
* @return {?}
*/
Dictionary.prototype.containsValue = /**
* @param {?} value
* @return {?}
*/
function (value) {
return this.any(( /**
* @param {?} x
* @return {?}
*/function (x) { return objCompare(x.value, value); }));
};
/**
* @param {?} key
* @return {?}
*/
Dictionary.prototype.tryGetValue = /**
* @param {?} key
* @return {?}
*/
function (key) {
/** @type {?} */
var item = this.singleOrDefault(( /**
* @param {?} x
* @return {?}
*/function (x) { return objCompare(x.key, key); }));
if (item) {
return item.value;
}
return null;
};
/* IEnumerable */
/* IEnumerable */
/**
* @return {?}
*/
Dictionary.prototype.asEnumerable = /* IEnumerable */
/**
* @return {?}
*/
function () {
return this;
};
Object.defineProperty(Dictionary.prototype, "length", {
get: /**
* @return {?}
*/ function () {
return this.list.length;
},
enumerable: true,
configurable: true
});
/**
* @param {?} index
* @return {?}
*/
Dictionary.prototype.elementAt = /**
* @param {?} index
* @return {?}
*/
function (index) {
try {
return this.list[index];
}
catch (e) {
return null;
}
};
/**
* @param {?=} predicate
* @return {?}
*/
Dictionary.prototype.any = /**
* @param {?=} predicate
* @return {?}
*/
function (predicate) {
if (!predicate) {
return this.list.length > 0;
}
for (var i = 0; i < this.list.length; i++) {
if (predicate(this.list[i])) {
return true;
}
}
return false;
};
/**
* @param {?=} predicate
* @return {?}
*/
Dictionary.prototype.all = /**
* @param {?=} predicate
* @return {?}
*/
function (predicate) {
if (!predicate) {
return this.list.length > 0;
}
for (var i = 0; i < this.list.length; i++) {
if (!predicate(this.list[i])) {
return false;
}
}
return true;
};
/**
* @param {?=} predicate
* @return {?}
*/
Dictionary.prototype.single = /**
* @param {?=} predicate
* @return {?}
*/
function (predicate) {
if (predicate === void 0) {
predicate = null;
}
if (this.list.length <= 0) {
throw ITEM_NOT_FOUND_MSG;
}
if (predicate) {
/** @type {?} */
var item = this.singleOrDefault(predicate);
if (!item) {
throw ITEM_NOT_FOUND_MSG;
}
return item;
}
return this.list[0];
};
/**
* @param {?=} predicate
* @return {?}
*/
Dictionary.prototype.first = /**
* @param {?=} predicate
* @return {?}
*/
function (predicate) {
if (predicate === void 0) {
predicate = null;
}
if (this.list.length <= 0) {
throw ITEM_NOT_FOUND_MSG;
}
if (predicate) {
/** @type {?} */
var item = this.firstOrDefault(predicate);
if (!item) {
throw ITEM_NOT_FOUND_MSG;
}
return item;
}
return this.list[0];
};
/**
* @param {?} predicate
* @return {?}
*/
Dictionary.prototype.last = /**
* @param {?} predicate
* @return {?}
*/
function (predicate) {
if (this.list.length <= 0) {
throw ITEM_NOT_FOUND_MSG;
}
if (predicate) {
/** @type {?} */
var item = this.lastOrDefault(predicate);
if (!item) {
throw ITEM_NOT_FOUND_MSG;
}
return item;
}
return this.list[this.list.length - 1];
};
/**
* @param {?} predicate
* @return {?}
*/
Dictionary.prototype.singleOrDefault = /**
* @param {?} predicate
* @return {?}
*/
function (predicate) {
/** @type {?} */
var temp = new Array();
this.list.filter(( /**
* @param {?} element
* @return {?}
*/function (element) {
if (predicate(element)) {
temp.push(element);
}
}));
if (temp.length > 1) {
throw MULTIPLE_INSTANCES_FOUND_MSG;
}
if (temp.length <= 0) {
return null;
}
return temp[0];
};
/**
* @param {?} predicate
* @return {?}
*/
Dictionary.prototype.firstOrDefault = /**
* @param {?} predicate
* @return {?}
*/
function (predicate) {
for (var i = 0; i < this.length; i++) {
/** @type {?} */
var item = this.list[i];
if (predicate(item)) {
return item;
}
}
return null;
};
/**
* @param {?} predicate
* @return {?}
*/
Dictionary.prototype.lastOrDefault = /**
* @param {?} predicate
* @return {?}
*/
function (predicate) {
for (var i = this.length; i >= 0; i--) {
/** @type {?} */
var item = this.list[i - 1];
if (predicate(item)) {
return item;
}
}
return null;
};
/**
* @param {?} predicate
* @return {?}
*/
Dictionary.prototype.where = /**
* @param {?} predicate
* @return {?}
*/
function (predicate) {
/** @type {?} */
var temp = new Dictionary();
this.list.filter(( /**
* @param {?} element
* @return {?}
*/function (element) {
if (predicate(element)) {
temp.add(element.key, element.value);
}
}));
return temp;
};
/**
* @template TResult
* @param {?} predicate
* @return {?}
*/
Dictionary.prototype.select = /**
* @template TResult
* @param {?} predicate
* @return {?}
*/
function (predicate) {
/** @type {?} */
var temp = new List();
this.forEach(( /**
* @param {?} x
* @return {?}
*/function (x) { return temp.add(predicate(x)); }));
return temp;
};
/**
* @param {?} predicate
* @return {?}
*/
Dictionary.prototype.forEach = /**
* @param {?} predicate
* @return {?}
*/
function (predicate) {
this.list.forEach(( /**
* @param {?} x
* @return {?}
*/function (x) { return predicate(x); }));
};
/**
* @return {?}
*/
Dictionary.prototype.toArray = /**
* @return {?}
*/
function () {
return this.list.slice();
};
/**
* @template TOuter, TMatch, TResult
* @param {?} outer
* @param {?} conditionInner
* @param {?} conditionOuter
* @param {?} select
* @param {?=} leftJoin
* @return {?}
*/
Dictionary.prototype.join = /**
* @template TOuter, TMatch, TResult
* @param {?} outer
* @param {?} conditionInner
* @param {?} conditionOuter
* @param {?} select
* @param {?=} leftJoin
* @return {?}
*/
function (outer, conditionInner, conditionOuter, select, leftJoin) {
if (leftJoin === void 0) {
leftJoin = false;
}
/** @type {?} */
var resultList = new List();
this.list.forEach(( /**
* @param {?} x
* @return {?}
*/function (x) {
/** @type {?} */
var outerEntries = outer.toArray().filter(( /**
* @param {?} y
* @return {?}
*/function (y) { return conditionInner(x) === conditionOuter(y); }));
if (leftJoin && outerEntries && outerEntries.length <= 0) {
resultList.add(select(x, null));
}
else {
outerEntries.forEach(( /**
* @param {?} z
* @return {?}
*/function (z) { return resultList.add(select(x, z)); }));
}
}));
return resultList;
};
/**
* @param {?} predicate
* @return {?}
*/
Dictionary.prototype.groupBy = /**
* @param {?} predicate
* @return {?}
*/
function (predicate) {
/** @type {?} */
var groups = {};
this.list.forEach(( /**
* @param {?} o
* @return {?}
*/function (o) {
/** @type {?} */
var group = JSON.stringify(predicate(o));
groups[group] = groups[group] || [];
groups[group].push(o);
}));
/** @type {?} */
var g = Object.keys(groups).map(( /**
* @param {?} group
* @return {?}
*/function (group) {
/** @type {?} */
var a = group.substr(1, group.length - 2);
/** @type {?} */
var grp = new Group(new List(a.split(',')).select(( /**
* @param {?} x
* @return {?}
*/function (x) { return x.replace(/^(")?(.*?)(")?$/ig, "$2"); })).toArray(), groups[group]);
return grp;
}));
return new List(g);
};
/**
* @template TResult
* @param {?} predicate
* @return {?}
*/
Dictionary.prototype.selectMany = /**
* @template TResult
* @param {?} predicate
* @return {?}
*/
function (predicate) {
return this.list.reduce(( /**
* @param {?} out
* @param {?} inx
* @return {?}
*/function (out, inx) {
/** @type {?} */
var items = predicate(inx);
out.addRange(items);
return out;
}), new List(new Array()));
};
/**
* @param {?} comparer
* @return {?}
*/
Dictionary.prototype.orderBy = /**
* @param {?} comparer
* @return {?}
*/
function (comparer) {
/** @type {?} */
var temp = this.list.sort(( /**
* @param {?} x
* @param {?} y
* @return {?}
*/function (x, y) { return comparer.compare(x, y); }));
return new List(temp);
};
/**
* @param {?} comparer
* @return {?}
*/
Dictionary.prototype.distinct = /**
* @param {?} comparer
* @return {?}
*/
function (comparer) {
/** @type {?} */
var uniques = new List();
this.forEach(( /**
* @param {?} x
* @return {?}
*/function (x) {
if (uniques.length > 0) {
if (!uniques.any(( /**
* @param {?} y
* @return {?}
*/function (y) { return comparer.equals(x, y); }))) {
uniques.add(x);
}
}
else {
uniques.add(x);
}
}));
return uniques;
};
/**
* @param {?} list
* @return {?}
*/
Dictionary.prototype.union = /**
* @param {?} list
* @return {?}
*/
function (list) {
this.addRange(list.toArray());
return this;
};
/**
* @return {?}
*/
Dictionary.prototype.reverse = /**
* @return {?}
*/
function () {
return new List(this.list.slice().reverse());
};
/**
* @param {?} no
* @return {?}
*/
Dictionary.prototype.skip = /**
* @param {?} no
* @return {?}
*/
function (no) {
if (no > 0) {
return new Dictionary(this.list.slice(no, this.list.length - 1));
}
return this;
};
/**
* @param {?} no
* @return {?}
*/
Dictionary.prototype.take = /**
* @param {?} no
* @return {?}
*/
function (no) {
if (no > 0) {
return new Dictionary(this.list.slice(0, no));
}
return this;
};
/**
* @param {?} predicate
* @return {?}
*/
Dictionary.prototype.sum = /**
* @param {?} predicate
* @return {?}
*/
function (predicate) {
/** @type {?} */
var sum = 0;
this.list.forEach(( /**
* @param {?} x
* @return {?}
*/function (x) { return sum = sum + predicate(x); }));
return sum;
};
/**
* @param {?} predicate
* @return {?}
*/
Dictionary.prototype.avg = /**
* @param {?} predicate
* @return {?}
*/
function (predicate) {
return this.sum(predicate) / this.length;
};
/**
* @param {?} predicate
* @return {?}
*/
Dictionary.prototype.min = /**
* @param {?} predicate
* @return {?}
*/
function (predicate) {
/** @type {?} */
var min = 0;
/** @type {?} */
var i = 0;
this.list.forEach(( /**
* @param {?} x
* @return {?}
*/function (x) {
if (i == 0) {
min = predicate(x);
}
else {
/** @type {?} */
var val = predicate(x);
if (val < min) {
min = val;
}
}
i++;
}));
return min;
};
/**
* @param {?} predicate
* @return {?}
*/
Dictionary.prototype.max = /**
* @param {?} predicate
* @return {?}
*/
function (predicate) {
/** @type {?} */
var max = 0;
/** @type {?} */
var i = 0;
this.list.forEach(( /**
* @param {?} x
* @return {?}
*/function (x) {
if (i == 0) {
max = predicate(x);
}
else {
/** @type {?} */
var val = predicate(x);
if (val > max) {
max = val;
}
}
i++;
}));
return max;
};
/**
* @param {?=} predicate
* @return {?}
*/
Dictionary.prototype.count = /**
* @param {?=} predicate
* @return {?}
*/
function (predicate) {
if (predicate === void 0) {
predicate = null;
}
if (!predicate) {
return this.length;
}
/** @type {?} */
var count = 0;
this.list.forEach(( /**
* @param {?} x
* @return {?}
*/function (x) {
if (predicate(x)) {
count++;
}
}));
return count;
};
return Dictionary;
}());
/**
* @template TKey, TValue
*/
var /**
* @template TKey, TValue
*/ KeyValuePair = /** @class */ (function () {
function KeyValuePair(key, value) {
this.key = key;
this.value = value;
}
return KeyValuePair;
}());
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/**
* @template TKey
*/
var /**
* @template TKey
*/ StringComparer = /** @class */ (function () {
function StringComparer() {
}
/**
* @param {?} x
* @param {?} y
* @return {?}
*/
StringComparer.prototype.compare = /**
* @param {?} x
* @param {?} y
* @return {?}
*/
function (x, y) {
/** @type {?} */
var xKey = ( /** @type {?} */(( /** @type {?} */(x))));
/** @type {?} */
var yKey = ( /** @type {?} */(( /** @type {?} */(y))));
if (xKey > yKey) {
return 1;
}
else if (xKey == yKey) {
return 0;
}
else {
return -1;
}
};
return StringComparer;
}());
/**
* @template TKey
*/
var /**
* @template TKey
*/ NumberComparer = /** @class */ (function () {
function NumberComparer() {
}
/**
* @param {?} x
* @param {?} y
* @return {?}
*/
NumberComparer.prototype.compare = /**
* @param {?} x
* @param {?} y
* @return {?}
*/
function (x, y) {
/** @type {?} */
var xKey = ( /** @type {?} */(( /** @type {?} */(x))));
/** @type {?} */
var yKey = ( /** @type {?} */(( /** @type {?} */(y))));
if (xKey > yKey) {
return 1;
}
else if (xKey == yKey) {
return 0;
}
else {
return -1;
}
};
return NumberComparer;
}());
/**
* @template TKey, TValue
*/
var /**
* @template TKey, TValue
*/ SortedDictionary = /** @class */ (function () {
function SortedDictionary(comparer, list) {
if (list === void 0) {
list = null;
}
var _this = this;
this.list = new Array();
if (list) {
this.list = list;
}
this.comparer = comparer;
if (this.list && this.list.length > 0) {
if (this.comparer) {
this.list.sort(( /**
* @param {?} x
* @param {?} y
* @return {?}
*/function (x, y) { return _this.comparer.compare(x.key, y.key); }));
}
else {
/** @type {?} */
var value = this.list[0].key;
if (typeof value === "string") {
this.comparer = new StringComparer();
this.list = this.list.sort(( /**
* @param {?} x
* @param {?} y
* @return {?}
*/function (x, y) { return _this.comparer.compare(x.key, y.key); }));
}
else if (typeof value === "number") {
this.comparer = new NumberComparer();
this.list = this.list.sort(( /**
* @param {?} x
* @param {?} y
* @re