linq4js
Version:
Linq methods for JavaScript/TypeScript to work with Arrays
1 lines • 23 kB
JavaScript
;var Linq4JS;!function(Linq4JS){var GeneratedEntity=function(){function GeneratedEntity(){}return GeneratedEntity}();Linq4JS.GeneratedEntity=GeneratedEntity}(Linq4JS||(Linq4JS={}));var Linq4JS;!function(Linq4JS){var EvaluateCommand=function(){function EvaluateCommand(command){for(var identifier=[],_i=1;_i<arguments.length;_i++)identifier[_i-1]=arguments[_i];this.SplitRegex=[],this.Finder=[],this.Command=command;for(var _a=0,identifier_1=identifier;_a<identifier_1.length;_a++){var id=identifier_1[_a],sSplitRegex=void 0,sFinder=void 0;-1!==id.indexOf("{x}")?id.indexOf("{x}")===id.length-3?(sSplitRegex="\\b"+id.replace(" {x}","")+"\\b",sFinder="\\b"+id.replace(" {x}","\\b (.*)")):(sSplitRegex="\\b"+id.replace(" {x}","\\b .*? \\b")+"\\b",sFinder="\\b"+id.replace(" {x} ","\\b (.*) \\b")+"\\b"):(sSplitRegex="\\b"+id+"\\b",sFinder="\\b"+id+"\\b"),this.Finder.push(new RegExp(sFinder,"i")),this.SplitRegex.push(new RegExp(sSplitRegex,"gi"))}}return EvaluateCommand}();Linq4JS.EvaluateCommand=EvaluateCommand;var EvaluateCommandResult=function(){function EvaluateCommandResult(cmd,fn){this.Command=cmd,this.DynamicFunction=fn}return EvaluateCommandResult}();Linq4JS.EvaluateCommandResult=EvaluateCommandResult}(Linq4JS||(Linq4JS={}));var Linq4JS;!function(Linq4JS){var Helper=function(){function Helper(){}return Helper.ConvertStringFunction=function(functionString,noAutoReturn,noBracketReplace){if(0===functionString.length)throw new Error("Linq4JS: Cannot convert empty string to function");var varnameString=functionString.substring(0,functionString.indexOf("=>")).split(" ").join("").split("(").join("").split(")").join(""),varnames=varnameString.split(","),func=functionString.substring(functionString.indexOf("=>")+"=>".length);return null!=noBracketReplace&&!1!==noBracketReplace||func.replace("{","").replace("}",""),func.split(".match(//gi)").join(""),null!=noAutoReturn&&!1!==noAutoReturn||null==func.match(/return(?=([^\"']*[\"'][^\"']*[\"'])*[^\"']*$)/g)&&(func="return "+func),Function.apply(void 0,varnames.concat([func]))},Helper.ConvertFunction=function(testFunction,noAutoReturn,noBracketReplace){var result;if("function"==typeof testFunction)result=testFunction;else{if("string"!=typeof testFunction)throw new Error("Linq4JS: Cannot use '"+testFunction+"' as function");result=Linq4JS.Helper.ConvertStringFunction(testFunction,noAutoReturn,noBracketReplace)}return result},Helper.OrderCompareFunction=function(valueSelector,a,b,invert){var value_a=valueSelector(a),value_b=valueSelector(b),type_a=typeof value_a,type_b=typeof value_b;if("string"===type_a&&type_a===type_b){var value_a_string=value_a;value_a_string=value_a_string.toLowerCase();var value_b_string=value_b;return value_b_string=value_b_string.toLowerCase(),value_a_string>value_b_string?!0===invert?-1:1:value_a_string<value_b_string?!0===invert?1:-1:0}if("number"===type_a&&type_a===type_b){var value_a_number=value_a,value_b_number=value_b;return!0===invert?value_b_number-value_a_number:value_a_number-value_b_number}if("boolean"===type_a&&type_a===type_b){var value_a_bool=value_a;return value_a_bool===value_b?0:!0===invert?value_a_bool?1:-1:value_a_bool?-1:1}return"undefined"===type_a&&type_a===type_b?0:"undefined"===type_a?invert?1:-1:"undefined"===type_b?invert?-1:1:0},Helper.SplitCommand=function(command){for(var splitIndexes=[],_i=0,_a=this.Commands;_i<_a.length;_i++)for(var cmd=_a[_i],_b=0,_c=cmd.SplitRegex;_b<_c.length;_b++)for(var split=_c[_b];;){var result=split.exec(command);if(null==result)break;splitIndexes.push(result.index)}var parts=[];splitIndexes=splitIndexes.Distinct().OrderBy(function(x){return x});for(var i=0;i<splitIndexes.length;i++)i===splitIndexes.length-1?parts.push(command.substr(splitIndexes[i])):parts.push(command.substr(splitIndexes[i],splitIndexes[i+1]-splitIndexes[i]));return parts},Helper.MatchCommand=function(cmd){for(var _i=0,_a=this.Commands;_i<_a.length;_i++)for(var command=_a[_i],_b=0,_c=command.Finder;_b<_c.length;_b++){var regex=_c[_b],result=cmd.match(regex);if(null!=result)return new Linq4JS.EvaluateCommandResult(command.Command,result[1])}throw new Error("Linq4JS: No matching command was found for '"+cmd+"'")},Helper.NonEnumerable=function(name,value){Object.defineProperty(Array.prototype,name,{value:value,enumerable:!1})},Helper.CreateArrayData=function(array,value){void 0===value&&(value={}),Object.defineProperty(array,"_linq4js_",{value:value,enumerable:!1})},Helper.Commands=[new Linq4JS.EvaluateCommand("Clone","clone"),new Linq4JS.EvaluateCommand("Reverse","reverse"),new Linq4JS.EvaluateCommand("Contains","contains {x}"),new Linq4JS.EvaluateCommand("Join","join {x}"),new Linq4JS.EvaluateCommand("Sum","sum {x}","sum"),new Linq4JS.EvaluateCommand("Average","average {x}","average"),new Linq4JS.EvaluateCommand("Where","where {x}"),new Linq4JS.EvaluateCommand("SelectMany","selectmany {x}","select many {x}","select {x} many"),new Linq4JS.EvaluateCommand("Select","select {x}"),new Linq4JS.EvaluateCommand("Get","get {x}"),new Linq4JS.EvaluateCommand("ForEach","foreach {x}","for each {x}"),new Linq4JS.EvaluateCommand("Count","count","count {x}"),new Linq4JS.EvaluateCommand("All","all {x}"),new Linq4JS.EvaluateCommand("Any","any {x}","any"),new Linq4JS.EvaluateCommand("TakeWhile","take while {x}","take {x} while","takewhile {x}"),new Linq4JS.EvaluateCommand("Take","take {x}"),new Linq4JS.EvaluateCommand("Skip","skip {x}"),new Linq4JS.EvaluateCommand("Min","min {x}","min"),new Linq4JS.EvaluateCommand("Max","max {x}","max"),new Linq4JS.EvaluateCommand("GroupBy","groupby {x}","group by {x}"),new Linq4JS.EvaluateCommand("Distinct","distinct {x}","distinct"),new Linq4JS.EvaluateCommand("FindLastIndex","findlastindex {x}","find last index {x}","findindex {x} last","find index {x} last"),new Linq4JS.EvaluateCommand("FindIndex","findfirstindex {x}","find first index {x}","findindex {x} first","find index {x} first","findindex {x}","find index {x}"),new Linq4JS.EvaluateCommand("OrderByDescending","orderby {x} descending","order by {x} descending","orderby descending {x}","orderbydescending {x}","order by descending {x}"),new Linq4JS.EvaluateCommand("OrderBy","orderby {x} ascending","order by {x} ascending","orderbyascending {x}","order by ascending {x}","orderby {x}","order by {x}"),new Linq4JS.EvaluateCommand("FirstOrDefault","firstordefault {x}","first or default {x}","firstordefault","first or default"),new Linq4JS.EvaluateCommand("LastOrDefault","lastordefault {x}","last or default {x}","lastordefault","last or default"),new Linq4JS.EvaluateCommand("SingleOrDefault","singleordefault {x}","single or default {x}","singleordefault","single or default"),new Linq4JS.EvaluateCommand("First","first {x}","first"),new Linq4JS.EvaluateCommand("Last","last {x}","last"),new Linq4JS.EvaluateCommand("Single","single {x}","single"),new Linq4JS.EvaluateCommand("ThenByDescending","thenby {x} descending","then by {x} descending","thenbydescending {x}","then by descending {x}"),new Linq4JS.EvaluateCommand("ThenBy","thenby {x} ascending","then by {x} ascending","thenbyascending {x}","then by ascending {x}","thenby {x}","then by {x}")],Helper}();Linq4JS.Helper=Helper}(Linq4JS||(Linq4JS={}));var Linq4JS;!function(Linq4JS){var OrderEntry=function(){function OrderEntry(_direction,_valueSelector){this.Direction=_direction,this.ValueSelector=_valueSelector}return OrderEntry}();Linq4JS.OrderEntry=OrderEntry;!function(OrderDirection){OrderDirection[OrderDirection.Ascending=0]="Ascending",OrderDirection[OrderDirection.Descending=1]="Descending"}(Linq4JS.OrderDirection||(Linq4JS.OrderDirection={}))}(Linq4JS||(Linq4JS={}));var Linq4JS;!function(Linq4JS){var SelectEntry=function(){function SelectEntry(n,p){this.name=n,this.property=p}return SelectEntry}();Linq4JS.SelectEntry=SelectEntry}(Linq4JS||(Linq4JS={})),Linq4JS.Helper.NonEnumerable("Add",function(object,generateId){if(null!=object){if(!0===generateId){var newIndex_1,castedObject=object,last=this.Where(function(x){return null!=x._GeneratedId_}).OrderBy(function(x){return x._GeneratedId_}).LastOrDefault();if(null!=last){for(newIndex_1=null!=last._GeneratedId_?last._GeneratedId_:1;this.Any(function(x){return x._GeneratedId_===newIndex_1});)newIndex_1++;castedObject._GeneratedId_=newIndex_1}else castedObject._GeneratedId_=1}this.push(object)}return this}),Linq4JS.Helper.NonEnumerable("AddRange",function(objects,generateId){var that=this;return objects.ForEach(function(x){that.Add(x,generateId)}),that}),Linq4JS.Helper.NonEnumerable("Aggregate",function(method,startVal){var result;result=null!=startVal?startVal:"";var methodFunction=Linq4JS.Helper.ConvertFunction(method);return this.ForEach(function(x){result=methodFunction(result,x)}),result}),Linq4JS.Helper.NonEnumerable("All",function(filter){return this.Count(filter)===this.Count()}),Linq4JS.Helper.NonEnumerable("Any",function(filter){return this.Count(filter)>0}),Linq4JS.Helper.NonEnumerable("Average",function(selector,filter){var result=0,array=this;return null!=filter&&(array=array.Where(filter)),null!=selector&&(array=array.Select(selector)),array.ForEach(function(x){result+=x}),result/array.Count()}),Linq4JS.Helper.NonEnumerable("Clone",function(){for(var newArray=[],_i=0,_a=this;_i<_a.length;_i++){var obj=_a[_i];newArray.Add(obj)}return newArray}),Linq4JS.Helper.NonEnumerable("Concat",function(array){return this.concat(array)}),Linq4JS.Helper.NonEnumerable("Contains",function(object){return this.Any(function(x){return x===object})}),Linq4JS.Helper.NonEnumerable("Count",function(filter){return null!=filter?this.Where(filter).length:this.length}),Linq4JS.Helper.NonEnumerable("Distinct",function(valueSelector){var that=this;if(null!=valueSelector){var valueSelectorFunction_1=Linq4JS.Helper.ConvertFunction(valueSelector);return this.Where(function(x,i){return that.FindIndex(function(y){return valueSelectorFunction_1(y)===valueSelectorFunction_1(x)})===i})}return this.Where(function(x,i){return that.FindIndex(function(y){return y===x})===i})}),Linq4JS.Helper.NonEnumerable("Evaluate",function(command){for(var commandParts=Linq4JS.Helper.SplitCommand(command),computeObject=this,_i=0,commandParts_1=commandParts;_i<commandParts_1.length;_i++){var cmd=commandParts_1[_i],cmdResult=Linq4JS.Helper.MatchCommand(cmd);computeObject=computeObject[cmdResult.Command](cmdResult.DynamicFunction)}return computeObject}),Linq4JS.Helper.NonEnumerable("FindIndex",function(filter){if(null!=filter){for(var filterFunction=Linq4JS.Helper.ConvertFunction(filter),i=0;i<this.length;i++){if(filterFunction(this[i]))return i}return-1}throw new Error("Linq4JS: You must define a filter")}),Linq4JS.Helper.NonEnumerable("FindLastIndex",function(filter){if(null!=filter){for(var filterFunction=Linq4JS.Helper.ConvertFunction(filter),i=this.length-1;i>=0;i--){if(!0===filterFunction(this[i]))return i}return-1}throw new Error("Linq4JS: You must define a filter")}),Linq4JS.Helper.NonEnumerable("First",function(filter){var result=this;if(null!=filter&&(result=this.Where(filter)),result.Any())return result.Get(0);throw new Error("Linq4JS: The First Entry was not found")}),Linq4JS.Helper.NonEnumerable("FirstOrDefault",function(filter){var result=this;return null!=filter&&(result=this.Where(filter)),result.Any()?result.Get(0):null}),Linq4JS.Helper.NonEnumerable("ForEach",function(action){for(var actionFunction=Linq4JS.Helper.ConvertFunction(action,!0),i=0;i<this.length;i++){var result=actionFunction(this[i],i);if(null!=result&&!0===result)break}return this}),Linq4JS.Helper.NonEnumerable("Get",function(index){return this[index]}),Linq4JS.Helper.NonEnumerable("GroupBy",function(selector){var prev,selectorFunction=Linq4JS.Helper.ConvertFunction(selector),newArray=[],ordered=this.OrderBy(selectorFunction),newSub=[];return ordered.ForEach(function(x){null!=prev?selectorFunction(prev)!==selectorFunction(x)&&(newArray.Add(newSub),newSub=[],Linq4JS.Helper.CreateArrayData(newSub,{}),newSub._linq4js_.GroupValue=selectorFunction(x)):(Linq4JS.Helper.CreateArrayData(newSub,{}),newSub._linq4js_.GroupValue=selectorFunction(x)),newSub.Add(x),prev=x}),newSub.Count()>0&&newArray.Add(newSub),newArray}),Linq4JS.Helper.NonEnumerable("Insert",function(object,index){return this.splice(index,0,object),this}),Linq4JS.Helper.NonEnumerable("Intersect",function(array){var that=this,newArray=[];return this.ForEach(function(x){array.Contains(x)&&newArray.Add(x)}),array.ForEach(function(x){that.Contains(x)&&newArray.Add(x)}),newArray.Distinct()}),Linq4JS.Helper.NonEnumerable("Join",function(char,selector){var array=this;return null!=selector&&(array=this.Select(selector)),array.join(char)}),Linq4JS.Helper.NonEnumerable("Last",function(filter){var result=this;if(null!=filter&&(result=this.Where(filter)),result.Any())return result.Get(result.length-1);throw new Error("Linq4JS: The Last Entry was not found")}),Linq4JS.Helper.NonEnumerable("LastOrDefault",function(filter){var result=this;return null!=filter&&(result=this.Where(filter)),result.Any()?result.Get(result.length-1):null}),Linq4JS.Helper.NonEnumerable("Max",function(valueSelector){if(null!=valueSelector){var valueSelectorFunction=Linq4JS.Helper.ConvertFunction(valueSelector);return this.OrderBy(valueSelectorFunction).LastOrDefault()}return this.OrderBy(function(x){return x}).LastOrDefault()}),Linq4JS.Helper.NonEnumerable("Min",function(valueSelector){if(null!=valueSelector){var valueSelectorFunction=Linq4JS.Helper.ConvertFunction(valueSelector);return this.OrderBy(valueSelectorFunction).FirstOrDefault()}return this.OrderBy(function(x){return x}).FirstOrDefault()}),Linq4JS.Helper.NonEnumerable("Move",function(oldIndex,newIndex){return this.splice(newIndex,0,this.splice(oldIndex,1)[0]),this}),Linq4JS.Helper.NonEnumerable("OrderBy",function(valueSelector){var valueSelectorFunction=Linq4JS.Helper.ConvertFunction(valueSelector),ordered=this.Clone();return Linq4JS.Helper.CreateArrayData(ordered,{}),ordered._linq4js_.Order=new Array(new Linq4JS.OrderEntry(Linq4JS.OrderDirection.Ascending,valueSelectorFunction)),ordered.sort(function(a,b){return Linq4JS.Helper.OrderCompareFunction(valueSelectorFunction,a,b,!1)})}),Linq4JS.Helper.NonEnumerable("OrderByDescending",function(valueSelector){var valueSelectorFunction=Linq4JS.Helper.ConvertFunction(valueSelector),ordered=this.Clone();return Linq4JS.Helper.CreateArrayData(ordered,{}),ordered._linq4js_.Order=new Array(new Linq4JS.OrderEntry(Linq4JS.OrderDirection.Descending,valueSelectorFunction)),ordered.sort(function(a,b){return Linq4JS.Helper.OrderCompareFunction(valueSelectorFunction,a,b,!0)})}),Linq4JS.Helper.NonEnumerable("Range",function(start,length){for(var newArray=[],i=start;i<start+length;i++)newArray.Add(this.Get(i));return newArray}),Linq4JS.Helper.NonEnumerable("Remove",function(object,primaryKeySelector){var targetIndex;if(null==object)throw new Error("Linq4JS: The object cannot be null");var castedObject=object;if(null!=primaryKeySelector){var selector_1=Linq4JS.Helper.ConvertFunction(primaryKeySelector);targetIndex=this.FindIndex(function(x){return selector_1(x)===selector_1(object)})}else targetIndex=null!=castedObject._GeneratedId_?this.FindIndex(function(x){return x._GeneratedId_===castedObject._GeneratedId_}):null!=castedObject.Id?this.FindIndex(function(x){return x.Id===castedObject.Id}):this.FindIndex(function(x){return x===object});if(-1===targetIndex)throw new Error("Linq4JS: Nothing found to Remove");return this.splice(targetIndex,1),this}),Linq4JS.Helper.NonEnumerable("RemoveRange",function(objects,primaryKeySelector){var that=this;if(null!=primaryKeySelector){var selector_2=Linq4JS.Helper.ConvertFunction(primaryKeySelector);objects.ForEach(function(x){that.Remove(x,selector_2)})}else objects.ForEach(function(x){that.Remove(x)});return that}),Linq4JS.Helper.NonEnumerable("Repeat",function(object,count){for(var i=0;i<count;i++)this.Add(object);return this}),Linq4JS.Helper.NonEnumerable("Reverse",function(){return this.Clone().reverse()}),Linq4JS.Helper.NonEnumerable("Select",function(selector){var selectorWork=selector;if("string"==typeof selectorWork){var selectStatement=selectorWork.substr(selectorWork.indexOf("=>")+"=>".length);if(null!=selectStatement.match(/^\s*{.*}\s*$/)){selectStatement=selectStatement.replace(/^\s*{(.*)}\s*$/,"$1");for(var parts=selectStatement.split(/,(?=(?:[^'"]*['"][^'"]*['"])*[^'"]*$)/g),newContent="",i=0;i<parts.length;i++){var part=parts[i];if(-1!==part.indexOf(":"))newContent+=part;else if(-1!==part.indexOf("="))newContent+=part.replace("=",":");else{var values=part.split("."),name_1=values[values.length-1];newContent+=name_1+":"+part}i<parts.length-1&&(newContent+=",")}selectorWork=selectorWork.substr(0,selectorWork.indexOf("=>"))+"=> return {"+newContent+"}"}}var selectorFunction=Linq4JS.Helper.ConvertFunction(selectorWork,!1,!0),newArray=[];this._linq4js_&&this._linq4js_.GroupValue&&(newArray._linq4js_={GroupValue:this._linq4js_.GroupValue,Order:[]});for(var _i=0,_a=this;_i<_a.length;_i++){var obj=_a[_i];newArray.Add(selectorFunction(obj))}return newArray}),Linq4JS.Helper.NonEnumerable("SelectMany",function(selector){var newArray=[],selectorFunction=Linq4JS.Helper.ConvertFunction(selector);return this.ForEach(function(item){var items=selectorFunction(item)||[];newArray.AddRange(items)}),newArray}),Linq4JS.Helper.NonEnumerable("SequenceEqual",function(array){if(this===array)return!0;if(null==this||null==array)return!1;if(this.length!==array.length)return!1;for(var i=0;i<this.length;i++){var currentObjectThis=this[i],currentObjectArray=array[i];if(currentObjectThis instanceof Array&¤tObjectArray instanceof Array){if(!currentObjectThis.SequenceEqual(currentObjectArray))return!1}else if(currentObjectThis instanceof Object&¤tObjectArray instanceof Object)for(var keys=Object.keys(currentObjectThis),_i=0,keys_1=keys;_i<keys_1.length;_i++){var key=keys_1[_i];if(currentObjectThis[key]!==currentObjectArray[key])return!1}else if(currentObjectThis!==currentObjectArray)return!1}return!0}),Linq4JS.Helper.NonEnumerable("Single",function(filter){var result=this;if(null!=filter&&(result=this.Where(filter)),1===result.Count())return result.Get(0);throw new Error("Linq4JS: The array does not contain exactly one element")}),Linq4JS.Helper.NonEnumerable("SingleOrDefault",function(filter){var result=this;if(null!=filter&&(result=this.Where(filter)),1===result.Count())return result.Get(0);if(result.Count()>1)throw new Error("Linq4JS: The array contains more than one element");return null}),Linq4JS.Helper.NonEnumerable("Skip",function(count){return this.slice(count,this.Count())}),Linq4JS.Helper.NonEnumerable("Sum",function(selector,filter){var result=0,array=this;return null!=filter&&(array=array.Where(filter)),null!=selector&&(array=array.Select(selector)),array.ForEach(function(x){result+=x}),result}),Linq4JS.Helper.NonEnumerable("Take",function(count){return this.slice(0,count)}),Linq4JS.Helper.NonEnumerable("TakeWhile",function(condition,initial,after){var conditionFunction=Linq4JS.Helper.ConvertFunction(condition),storage={};if(null!=initial){Linq4JS.Helper.ConvertFunction(initial)(storage)}var afterFunction=null;null!=after&&(afterFunction=Linq4JS.Helper.ConvertFunction(after));for(var result=[],_i=0,_a=this;_i<_a.length;_i++){var object=_a[_i];!0===conditionFunction(object,storage)&&(result.Add(object),null!=afterFunction&&afterFunction(object,storage))}return result}),Linq4JS.Helper.NonEnumerable("ThenBy",function(valueSelector){var valueSelectorFunction=Linq4JS.Helper.ConvertFunction(valueSelector);if(null==this._linq4js_||null==this._linq4js_.Order||0===this._linq4js_.Order.Count())throw new Error("Linq4JS: Please call OrderBy or OrderByDescending before ThenBy");var ordered=this;return ordered._linq4js_.Order.Add(new Linq4JS.OrderEntry(Linq4JS.OrderDirection.Ascending,valueSelectorFunction)),ordered.sort(function(a,b){for(var _i=0,_a=ordered._linq4js_.Order;_i<_a.length;_i++){var entry=_a[_i],result=Linq4JS.Helper.OrderCompareFunction(entry.ValueSelector,a,b,entry.Direction===Linq4JS.OrderDirection.Descending);if(0!==result)return result}return 0})}),Linq4JS.Helper.NonEnumerable("ThenByDescending",function(valueSelector){var valueSelectorFunction=Linq4JS.Helper.ConvertFunction(valueSelector);if(null==this._linq4js_||null==this._linq4js_.Order||0===this._linq4js_.Order.Count())throw new Error("Linq4JS: Please call OrderBy or OrderByDescending before ThenByDescending");var ordered=this;return ordered._linq4js_.Order.Add(new Linq4JS.OrderEntry(Linq4JS.OrderDirection.Descending,valueSelectorFunction)),ordered.sort(function(a,b){for(var _i=0,_a=ordered._linq4js_.Order;_i<_a.length;_i++){var entry=_a[_i],result=Linq4JS.Helper.OrderCompareFunction(entry.ValueSelector,a,b,entry.Direction===Linq4JS.OrderDirection.Descending);if(0!==result)return result}return 0})}),Linq4JS.Helper.NonEnumerable("ToDictionary",function(keySelector,valueSelector){var keySelectorFunction=Linq4JS.Helper.ConvertFunction(keySelector),returnObject={};if(null!=valueSelector){var valueSelectorFunction_2=Linq4JS.Helper.ConvertFunction(valueSelector);this.ForEach(function(x){returnObject[keySelectorFunction(x)]=valueSelectorFunction_2(x)})}else this.ForEach(function(x){returnObject[keySelectorFunction(x)]=x});return returnObject}),Linq4JS.Helper.NonEnumerable("Union",function(array){return this.Concat(array).Distinct()}),Linq4JS.Helper.NonEnumerable("Update",function(object,primaryKeySelector){var targetIndex;if(null==object)throw new Error("Linq4JS: The object cannot be null");var castedObject=object;if(null!=primaryKeySelector){var selector_3=Linq4JS.Helper.ConvertFunction(primaryKeySelector);targetIndex=this.FindIndex(function(x){return selector_3(x)===selector_3(object)})}else targetIndex=null!=castedObject._GeneratedId_?this.FindIndex(function(x){return x._GeneratedId_===castedObject._GeneratedId_}):null!=castedObject.Id?this.FindIndex(function(x){return x.Id===castedObject.Id}):this.FindIndex(function(x){return x===object});if(-1===targetIndex)throw new Error("Linq4JS: Nothing found to Update");for(var keys=Object.keys(object),_i=0,keys_2=keys;_i<keys_2.length;_i++){var key=keys_2[_i];"Id"!==key&&(this[targetIndex][key]=object[key])}return this}),Linq4JS.Helper.NonEnumerable("UpdateRange",function(objects,primaryKeySelector){var that=this;if(null!=primaryKeySelector){var selector_4=Linq4JS.Helper.ConvertFunction(primaryKeySelector);objects.ForEach(function(x){that.Update(x,selector_4)})}else objects.ForEach(function(x){that.Update(x)});return this}),Linq4JS.Helper.NonEnumerable("Where",function(filter){if(null!=filter){for(var filterFunction=Linq4JS.Helper.ConvertFunction(filter),newArray=[],i=0;i<this.length;i++){var obj=this[i];!0===filterFunction(obj,i)&&newArray.push(obj)}return newArray}throw new Error("Linq4JS: You must define a filter")}),Linq4JS.Helper.NonEnumerable("Zip",function(array,result){for(var resultFunction=Linq4JS.Helper.ConvertFunction(result),newArray=[],i=0;i<this.length;i++)null!=array[i]&&newArray.Add(resultFunction(this[i],array[i]));return newArray});