@newview/file-ui 1.1.14 → 1.1.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +0 -6
- package/dist/file-ui.js +2682 -11
- package/dist/file-ui.umd.cjs +1 -1
- package/package.json +2 -4
- package/types/DictionaryTools.d.ts +10 -0
- package/vite.config.ts +1 -4
package/dist/file-ui.js
CHANGED
|
@@ -6,11 +6,10 @@ var __publicField = (obj, key, value) => {
|
|
|
6
6
|
};
|
|
7
7
|
import { BaseInstance } from "@newview/base-vue";
|
|
8
8
|
import { defineComponent, ref, watch, resolveComponent, openBlock, createElementBlock, Fragment, createVNode, withCtx, createElementVNode, reactive, renderList, createBlock, createSlots, normalizeClass, withModifiers, createCommentVNode, toDisplayString, createTextVNode, pushScopeId, popScopeId, onMounted, onBeforeUnmount, nextTick, h, watchEffect, normalizeStyle, withDirectives, vShow, vModelText } from "vue";
|
|
9
|
-
import { QueryWrapper } from "@newview/infrastructure";
|
|
9
|
+
import { QueryWrapper, storageInfo } from "@newview/infrastructure";
|
|
10
10
|
import { OSSFileApi, FileApi, UploadApi, FileInfoApi } from "@newview/fileservice-api";
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import linq from "linq";
|
|
11
|
+
import { DictionaryDetailApi, DataStructureApi, StructureInstanceApi } from "@newview/basics-api";
|
|
12
|
+
import { utilities } from "@newview/tools";
|
|
14
13
|
const propDefine$6 = {
|
|
15
14
|
modelValue: {
|
|
16
15
|
// 是否显示
|
|
@@ -15468,6 +15467,21 @@ function _sfc_render$3(_ctx, _cache, $props, $setup, $data, $options) {
|
|
|
15468
15467
|
}, 8, ["onlyView", "formItems", "formModel"]);
|
|
15469
15468
|
}
|
|
15470
15469
|
const ComFormUp = /* @__PURE__ */ _export_sfc(_sfc_main$3, [["render", _sfc_render$3]]);
|
|
15470
|
+
const dictionaryDetailApi = new DictionaryDetailApi();
|
|
15471
|
+
const loadDictionaryData = async (optionCode, source, iViewOptions, platformId) => {
|
|
15472
|
+
if (!source) {
|
|
15473
|
+
source = [];
|
|
15474
|
+
}
|
|
15475
|
+
if (utilities.isNull(platformId)) {
|
|
15476
|
+
platformId = storageInfo.getCurrentPlatform().Id;
|
|
15477
|
+
}
|
|
15478
|
+
const res = utilities.parseApiResult(await dictionaryDetailApi.getOptions(platformId, optionCode));
|
|
15479
|
+
if (iViewOptions) {
|
|
15480
|
+
source.splice(0, 0, ...utilities.arrayHelper.parseIViewOptions(res, "DetailInfor", "DetailValue"));
|
|
15481
|
+
return source;
|
|
15482
|
+
}
|
|
15483
|
+
return res;
|
|
15484
|
+
};
|
|
15471
15485
|
const propDefine$2 = {
|
|
15472
15486
|
code: {
|
|
15473
15487
|
// 字典码
|
|
@@ -15547,6 +15561,2663 @@ function _sfc_render$2(_ctx, _cache, $props, $setup, $data, $options) {
|
|
|
15547
15561
|
}, 8, ["disabled", "modelValue", "onOnChange"]);
|
|
15548
15562
|
}
|
|
15549
15563
|
const NvDicSelect = /* @__PURE__ */ _export_sfc(_sfc_main$2, [["render", _sfc_render$2]]);
|
|
15564
|
+
var Functions = {
|
|
15565
|
+
Identity: function(x) {
|
|
15566
|
+
return x;
|
|
15567
|
+
},
|
|
15568
|
+
True: function() {
|
|
15569
|
+
return true;
|
|
15570
|
+
},
|
|
15571
|
+
Blank: function() {
|
|
15572
|
+
}
|
|
15573
|
+
};
|
|
15574
|
+
var Types = {
|
|
15575
|
+
Boolean: "boolean",
|
|
15576
|
+
Number: "number",
|
|
15577
|
+
String: "string",
|
|
15578
|
+
Object: typeof {},
|
|
15579
|
+
Undefined: "undefined",
|
|
15580
|
+
Function: "function"
|
|
15581
|
+
};
|
|
15582
|
+
var funcCache = { "": Functions.Identity };
|
|
15583
|
+
var Utils = {
|
|
15584
|
+
createLambda: function(expression) {
|
|
15585
|
+
if (expression == null)
|
|
15586
|
+
return Functions.Identity;
|
|
15587
|
+
if (typeof expression === Types.String) {
|
|
15588
|
+
let f = funcCache[expression];
|
|
15589
|
+
if (f != null) {
|
|
15590
|
+
return f;
|
|
15591
|
+
}
|
|
15592
|
+
if (expression.indexOf("=>") === -1) {
|
|
15593
|
+
const regexp = new RegExp("[$]+", "g");
|
|
15594
|
+
let maxLength = 0;
|
|
15595
|
+
let match;
|
|
15596
|
+
while ((match = regexp.exec(expression)) != null) {
|
|
15597
|
+
if (match[0].length > maxLength) {
|
|
15598
|
+
maxLength = match[0].length;
|
|
15599
|
+
}
|
|
15600
|
+
}
|
|
15601
|
+
const argArray = [];
|
|
15602
|
+
for (let i = 1; i <= maxLength; i++) {
|
|
15603
|
+
let dollar = "";
|
|
15604
|
+
for (let j = 0; j < i; j++) {
|
|
15605
|
+
dollar += "$";
|
|
15606
|
+
}
|
|
15607
|
+
argArray.push(dollar);
|
|
15608
|
+
}
|
|
15609
|
+
const args = argArray.join(",");
|
|
15610
|
+
f = new Function(args, "return " + expression);
|
|
15611
|
+
funcCache[expression] = f;
|
|
15612
|
+
return f;
|
|
15613
|
+
} else {
|
|
15614
|
+
const expr = expression.match(/^[(\s]*([^()]*?)[)\s]*=>(.*)/);
|
|
15615
|
+
f = new Function(expr[1], expr[2].match(/\breturn\b/) ? expr[2] : "return " + expr[2]);
|
|
15616
|
+
funcCache[expression] = f;
|
|
15617
|
+
return f;
|
|
15618
|
+
}
|
|
15619
|
+
}
|
|
15620
|
+
return expression;
|
|
15621
|
+
},
|
|
15622
|
+
defineProperty: function(target, methodName, value) {
|
|
15623
|
+
Object.defineProperty(target, methodName, {
|
|
15624
|
+
enumerable: false,
|
|
15625
|
+
configurable: true,
|
|
15626
|
+
writable: true,
|
|
15627
|
+
value
|
|
15628
|
+
});
|
|
15629
|
+
},
|
|
15630
|
+
compare: function(a, b) {
|
|
15631
|
+
return a === b ? 0 : a > b ? 1 : -1;
|
|
15632
|
+
},
|
|
15633
|
+
dispose: function(obj) {
|
|
15634
|
+
if (obj != null)
|
|
15635
|
+
obj.dispose();
|
|
15636
|
+
},
|
|
15637
|
+
hasNativeIteratorSupport: function() {
|
|
15638
|
+
return typeof Symbol !== "undefined" && typeof Symbol.iterator !== "undefined";
|
|
15639
|
+
}
|
|
15640
|
+
};
|
|
15641
|
+
var State = { Before: 0, Running: 1, After: 2 };
|
|
15642
|
+
var IEnumerator = function(initialize, tryGetNext, dispose) {
|
|
15643
|
+
var yielder = new Yielder();
|
|
15644
|
+
var state = State.Before;
|
|
15645
|
+
this.current = yielder.current;
|
|
15646
|
+
this.moveNext = function() {
|
|
15647
|
+
try {
|
|
15648
|
+
switch (state) {
|
|
15649
|
+
case State.Before:
|
|
15650
|
+
state = State.Running;
|
|
15651
|
+
initialize();
|
|
15652
|
+
case State.Running:
|
|
15653
|
+
if (tryGetNext.apply(yielder)) {
|
|
15654
|
+
return true;
|
|
15655
|
+
} else {
|
|
15656
|
+
this.dispose();
|
|
15657
|
+
return false;
|
|
15658
|
+
}
|
|
15659
|
+
case State.After:
|
|
15660
|
+
return false;
|
|
15661
|
+
}
|
|
15662
|
+
} catch (e) {
|
|
15663
|
+
this.dispose();
|
|
15664
|
+
throw e;
|
|
15665
|
+
}
|
|
15666
|
+
};
|
|
15667
|
+
this.dispose = function() {
|
|
15668
|
+
if (state != State.Running)
|
|
15669
|
+
return;
|
|
15670
|
+
try {
|
|
15671
|
+
dispose();
|
|
15672
|
+
} finally {
|
|
15673
|
+
state = State.After;
|
|
15674
|
+
}
|
|
15675
|
+
};
|
|
15676
|
+
};
|
|
15677
|
+
var Yielder = function() {
|
|
15678
|
+
var current = null;
|
|
15679
|
+
this.current = function() {
|
|
15680
|
+
return current;
|
|
15681
|
+
};
|
|
15682
|
+
this.yieldReturn = function(value) {
|
|
15683
|
+
current = value;
|
|
15684
|
+
return true;
|
|
15685
|
+
};
|
|
15686
|
+
this.yieldBreak = function() {
|
|
15687
|
+
return false;
|
|
15688
|
+
};
|
|
15689
|
+
};
|
|
15690
|
+
var Enumerable = function(getEnumerator) {
|
|
15691
|
+
this.getEnumerator = getEnumerator;
|
|
15692
|
+
};
|
|
15693
|
+
Enumerable.Utils = {};
|
|
15694
|
+
Enumerable.Utils.createLambda = function(expression) {
|
|
15695
|
+
return Utils.createLambda(expression);
|
|
15696
|
+
};
|
|
15697
|
+
Enumerable.Utils.createEnumerable = function(getEnumerator) {
|
|
15698
|
+
return new Enumerable(getEnumerator);
|
|
15699
|
+
};
|
|
15700
|
+
Enumerable.Utils.createEnumerator = function(initialize, tryGetNext, dispose) {
|
|
15701
|
+
return new IEnumerator(initialize, tryGetNext, dispose);
|
|
15702
|
+
};
|
|
15703
|
+
Enumerable.Utils.extendTo = function(type) {
|
|
15704
|
+
var typeProto = type.prototype;
|
|
15705
|
+
var enumerableProto;
|
|
15706
|
+
if (type === Array) {
|
|
15707
|
+
enumerableProto = ArrayEnumerable.prototype;
|
|
15708
|
+
Utils.defineProperty(typeProto, "getSource", function() {
|
|
15709
|
+
return this;
|
|
15710
|
+
});
|
|
15711
|
+
} else {
|
|
15712
|
+
enumerableProto = Enumerable.prototype;
|
|
15713
|
+
Utils.defineProperty(typeProto, "getEnumerator", function() {
|
|
15714
|
+
return Enumerable.from(this).getEnumerator();
|
|
15715
|
+
});
|
|
15716
|
+
}
|
|
15717
|
+
for (let methodName in enumerableProto) {
|
|
15718
|
+
const func = enumerableProto[methodName];
|
|
15719
|
+
if (typeProto[methodName] == func)
|
|
15720
|
+
continue;
|
|
15721
|
+
if (typeProto[methodName] != null) {
|
|
15722
|
+
methodName = methodName + "ByLinq";
|
|
15723
|
+
if (typeProto[methodName] == func)
|
|
15724
|
+
continue;
|
|
15725
|
+
}
|
|
15726
|
+
if (func instanceof Function) {
|
|
15727
|
+
Utils.defineProperty(typeProto, methodName, func);
|
|
15728
|
+
}
|
|
15729
|
+
}
|
|
15730
|
+
};
|
|
15731
|
+
Enumerable.Utils.recallFrom = function(type) {
|
|
15732
|
+
var typeProto = type.prototype;
|
|
15733
|
+
var enumerableProto;
|
|
15734
|
+
if (type === Array) {
|
|
15735
|
+
enumerableProto = ArrayEnumerable.prototype;
|
|
15736
|
+
delete typeProto.getSource;
|
|
15737
|
+
} else {
|
|
15738
|
+
enumerableProto = Enumerable.prototype;
|
|
15739
|
+
delete typeProto.getEnumerator;
|
|
15740
|
+
}
|
|
15741
|
+
for (const methodName in enumerableProto) {
|
|
15742
|
+
const func = enumerableProto[methodName];
|
|
15743
|
+
if (typeProto[methodName + "ByLinq"]) {
|
|
15744
|
+
delete typeProto[methodName + "ByLinq"];
|
|
15745
|
+
} else if (typeProto[methodName] == func && func instanceof Function) {
|
|
15746
|
+
delete typeProto[methodName];
|
|
15747
|
+
}
|
|
15748
|
+
}
|
|
15749
|
+
};
|
|
15750
|
+
Enumerable.choice = function() {
|
|
15751
|
+
var args = arguments;
|
|
15752
|
+
return new Enumerable(function() {
|
|
15753
|
+
return new IEnumerator(
|
|
15754
|
+
function() {
|
|
15755
|
+
args = args[0] instanceof Array ? args[0] : args[0].getEnumerator != null ? args[0].toArray() : args;
|
|
15756
|
+
},
|
|
15757
|
+
function() {
|
|
15758
|
+
return this.yieldReturn(args[Math.floor(Math.random() * args.length)]);
|
|
15759
|
+
},
|
|
15760
|
+
Functions.Blank
|
|
15761
|
+
);
|
|
15762
|
+
});
|
|
15763
|
+
};
|
|
15764
|
+
Enumerable.cycle = function() {
|
|
15765
|
+
var args = arguments;
|
|
15766
|
+
return new Enumerable(function() {
|
|
15767
|
+
var index = 0;
|
|
15768
|
+
return new IEnumerator(
|
|
15769
|
+
function() {
|
|
15770
|
+
args = args[0] instanceof Array ? args[0] : args[0].getEnumerator != null ? args[0].toArray() : args;
|
|
15771
|
+
},
|
|
15772
|
+
function() {
|
|
15773
|
+
if (index >= args.length)
|
|
15774
|
+
index = 0;
|
|
15775
|
+
return this.yieldReturn(args[index++]);
|
|
15776
|
+
},
|
|
15777
|
+
Functions.Blank
|
|
15778
|
+
);
|
|
15779
|
+
});
|
|
15780
|
+
};
|
|
15781
|
+
Enumerable.empty = function() {
|
|
15782
|
+
return new Enumerable(function() {
|
|
15783
|
+
return new IEnumerator(
|
|
15784
|
+
Functions.Blank,
|
|
15785
|
+
function() {
|
|
15786
|
+
return false;
|
|
15787
|
+
},
|
|
15788
|
+
Functions.Blank
|
|
15789
|
+
);
|
|
15790
|
+
});
|
|
15791
|
+
};
|
|
15792
|
+
Enumerable.from = function(obj) {
|
|
15793
|
+
if (obj == null) {
|
|
15794
|
+
return Enumerable.empty();
|
|
15795
|
+
}
|
|
15796
|
+
if (obj instanceof Enumerable) {
|
|
15797
|
+
return obj;
|
|
15798
|
+
}
|
|
15799
|
+
if (typeof obj == Types.Number || typeof obj == Types.Boolean) {
|
|
15800
|
+
return Enumerable.repeat(obj, 1);
|
|
15801
|
+
}
|
|
15802
|
+
if (typeof obj == Types.String) {
|
|
15803
|
+
return new Enumerable(function() {
|
|
15804
|
+
var index = 0;
|
|
15805
|
+
return new IEnumerator(
|
|
15806
|
+
Functions.Blank,
|
|
15807
|
+
function() {
|
|
15808
|
+
return index < obj.length ? this.yieldReturn(obj.charAt(index++)) : false;
|
|
15809
|
+
},
|
|
15810
|
+
Functions.Blank
|
|
15811
|
+
);
|
|
15812
|
+
});
|
|
15813
|
+
}
|
|
15814
|
+
if (typeof obj != Types.Function) {
|
|
15815
|
+
if (typeof obj.length == Types.Number) {
|
|
15816
|
+
return new ArrayEnumerable(obj);
|
|
15817
|
+
}
|
|
15818
|
+
if (typeof Symbol !== "undefined" && typeof obj[Symbol.iterator] !== "undefined") {
|
|
15819
|
+
return new Enumerable(function() {
|
|
15820
|
+
return new IEnumerator(
|
|
15821
|
+
Functions.Blank,
|
|
15822
|
+
function() {
|
|
15823
|
+
var next = obj.next();
|
|
15824
|
+
return next.done ? false : this.yieldReturn(next.value);
|
|
15825
|
+
},
|
|
15826
|
+
Functions.Blank
|
|
15827
|
+
);
|
|
15828
|
+
});
|
|
15829
|
+
}
|
|
15830
|
+
}
|
|
15831
|
+
return new Enumerable(function() {
|
|
15832
|
+
var array = [];
|
|
15833
|
+
var index = 0;
|
|
15834
|
+
return new IEnumerator(
|
|
15835
|
+
function() {
|
|
15836
|
+
for (const key in obj) {
|
|
15837
|
+
const value = obj[key];
|
|
15838
|
+
if (!(value instanceof Function) && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
15839
|
+
array.push({ key, value });
|
|
15840
|
+
}
|
|
15841
|
+
}
|
|
15842
|
+
},
|
|
15843
|
+
function() {
|
|
15844
|
+
return index < array.length ? this.yieldReturn(array[index++]) : false;
|
|
15845
|
+
},
|
|
15846
|
+
Functions.Blank
|
|
15847
|
+
);
|
|
15848
|
+
});
|
|
15849
|
+
}, Enumerable.make = function(element) {
|
|
15850
|
+
return Enumerable.repeat(element, 1);
|
|
15851
|
+
};
|
|
15852
|
+
Enumerable.matches = function(input, pattern, flags) {
|
|
15853
|
+
if (flags == null)
|
|
15854
|
+
flags = "";
|
|
15855
|
+
if (pattern instanceof RegExp) {
|
|
15856
|
+
flags += pattern.ignoreCase ? "i" : "";
|
|
15857
|
+
flags += pattern.multiline ? "m" : "";
|
|
15858
|
+
pattern = pattern.source;
|
|
15859
|
+
}
|
|
15860
|
+
if (flags.indexOf("g") === -1)
|
|
15861
|
+
flags += "g";
|
|
15862
|
+
return new Enumerable(function() {
|
|
15863
|
+
var regex;
|
|
15864
|
+
return new IEnumerator(
|
|
15865
|
+
function() {
|
|
15866
|
+
regex = new RegExp(pattern, flags);
|
|
15867
|
+
},
|
|
15868
|
+
function() {
|
|
15869
|
+
var match = regex.exec(input);
|
|
15870
|
+
return match ? this.yieldReturn(match) : false;
|
|
15871
|
+
},
|
|
15872
|
+
Functions.Blank
|
|
15873
|
+
);
|
|
15874
|
+
});
|
|
15875
|
+
};
|
|
15876
|
+
Enumerable.range = function(start, count, step) {
|
|
15877
|
+
if (step == null)
|
|
15878
|
+
step = 1;
|
|
15879
|
+
return new Enumerable(function() {
|
|
15880
|
+
var value;
|
|
15881
|
+
var index = 0;
|
|
15882
|
+
return new IEnumerator(
|
|
15883
|
+
function() {
|
|
15884
|
+
value = start - step;
|
|
15885
|
+
},
|
|
15886
|
+
function() {
|
|
15887
|
+
return index++ < count ? this.yieldReturn(value += step) : this.yieldBreak();
|
|
15888
|
+
},
|
|
15889
|
+
Functions.Blank
|
|
15890
|
+
);
|
|
15891
|
+
});
|
|
15892
|
+
};
|
|
15893
|
+
Enumerable.rangeDown = function(start, count, step) {
|
|
15894
|
+
if (step == null)
|
|
15895
|
+
step = 1;
|
|
15896
|
+
return new Enumerable(function() {
|
|
15897
|
+
var value;
|
|
15898
|
+
var index = 0;
|
|
15899
|
+
return new IEnumerator(
|
|
15900
|
+
function() {
|
|
15901
|
+
value = start + step;
|
|
15902
|
+
},
|
|
15903
|
+
function() {
|
|
15904
|
+
return index++ < count ? this.yieldReturn(value -= step) : this.yieldBreak();
|
|
15905
|
+
},
|
|
15906
|
+
Functions.Blank
|
|
15907
|
+
);
|
|
15908
|
+
});
|
|
15909
|
+
};
|
|
15910
|
+
Enumerable.rangeTo = function(start, to, step) {
|
|
15911
|
+
if (step == null)
|
|
15912
|
+
step = 1;
|
|
15913
|
+
if (start < to) {
|
|
15914
|
+
return new Enumerable(function() {
|
|
15915
|
+
var value;
|
|
15916
|
+
return new IEnumerator(
|
|
15917
|
+
function() {
|
|
15918
|
+
value = start - step;
|
|
15919
|
+
},
|
|
15920
|
+
function() {
|
|
15921
|
+
var next = value += step;
|
|
15922
|
+
return next <= to ? this.yieldReturn(next) : this.yieldBreak();
|
|
15923
|
+
},
|
|
15924
|
+
Functions.Blank
|
|
15925
|
+
);
|
|
15926
|
+
});
|
|
15927
|
+
} else {
|
|
15928
|
+
return new Enumerable(function() {
|
|
15929
|
+
var value;
|
|
15930
|
+
return new IEnumerator(
|
|
15931
|
+
function() {
|
|
15932
|
+
value = start + step;
|
|
15933
|
+
},
|
|
15934
|
+
function() {
|
|
15935
|
+
var next = value -= step;
|
|
15936
|
+
return next >= to ? this.yieldReturn(next) : this.yieldBreak();
|
|
15937
|
+
},
|
|
15938
|
+
Functions.Blank
|
|
15939
|
+
);
|
|
15940
|
+
});
|
|
15941
|
+
}
|
|
15942
|
+
};
|
|
15943
|
+
Enumerable.repeat = function(element, count) {
|
|
15944
|
+
if (count != null)
|
|
15945
|
+
return Enumerable.repeat(element).take(count);
|
|
15946
|
+
return new Enumerable(function() {
|
|
15947
|
+
return new IEnumerator(
|
|
15948
|
+
Functions.Blank,
|
|
15949
|
+
function() {
|
|
15950
|
+
return this.yieldReturn(element);
|
|
15951
|
+
},
|
|
15952
|
+
Functions.Blank
|
|
15953
|
+
);
|
|
15954
|
+
});
|
|
15955
|
+
};
|
|
15956
|
+
Enumerable.repeatWithFinalize = function(initializer, finalizer) {
|
|
15957
|
+
initializer = Utils.createLambda(initializer);
|
|
15958
|
+
finalizer = Utils.createLambda(finalizer);
|
|
15959
|
+
return new Enumerable(function() {
|
|
15960
|
+
var element;
|
|
15961
|
+
return new IEnumerator(
|
|
15962
|
+
function() {
|
|
15963
|
+
element = initializer();
|
|
15964
|
+
},
|
|
15965
|
+
function() {
|
|
15966
|
+
return this.yieldReturn(element);
|
|
15967
|
+
},
|
|
15968
|
+
function() {
|
|
15969
|
+
if (element != null) {
|
|
15970
|
+
finalizer(element);
|
|
15971
|
+
element = null;
|
|
15972
|
+
}
|
|
15973
|
+
}
|
|
15974
|
+
);
|
|
15975
|
+
});
|
|
15976
|
+
};
|
|
15977
|
+
Enumerable.generate = function(func, count) {
|
|
15978
|
+
if (count != null)
|
|
15979
|
+
return Enumerable.generate(func).take(count);
|
|
15980
|
+
func = Utils.createLambda(func);
|
|
15981
|
+
return new Enumerable(function() {
|
|
15982
|
+
return new IEnumerator(
|
|
15983
|
+
Functions.Blank,
|
|
15984
|
+
function() {
|
|
15985
|
+
return this.yieldReturn(func());
|
|
15986
|
+
},
|
|
15987
|
+
Functions.Blank
|
|
15988
|
+
);
|
|
15989
|
+
});
|
|
15990
|
+
};
|
|
15991
|
+
Enumerable.toInfinity = function(start, step) {
|
|
15992
|
+
if (start == null)
|
|
15993
|
+
start = 0;
|
|
15994
|
+
if (step == null)
|
|
15995
|
+
step = 1;
|
|
15996
|
+
return new Enumerable(function() {
|
|
15997
|
+
var value;
|
|
15998
|
+
return new IEnumerator(
|
|
15999
|
+
function() {
|
|
16000
|
+
value = start - step;
|
|
16001
|
+
},
|
|
16002
|
+
function() {
|
|
16003
|
+
return this.yieldReturn(value += step);
|
|
16004
|
+
},
|
|
16005
|
+
Functions.Blank
|
|
16006
|
+
);
|
|
16007
|
+
});
|
|
16008
|
+
};
|
|
16009
|
+
Enumerable.toNegativeInfinity = function(start, step) {
|
|
16010
|
+
if (start == null)
|
|
16011
|
+
start = 0;
|
|
16012
|
+
if (step == null)
|
|
16013
|
+
step = 1;
|
|
16014
|
+
return new Enumerable(function() {
|
|
16015
|
+
var value;
|
|
16016
|
+
return new IEnumerator(
|
|
16017
|
+
function() {
|
|
16018
|
+
value = start + step;
|
|
16019
|
+
},
|
|
16020
|
+
function() {
|
|
16021
|
+
return this.yieldReturn(value -= step);
|
|
16022
|
+
},
|
|
16023
|
+
Functions.Blank
|
|
16024
|
+
);
|
|
16025
|
+
});
|
|
16026
|
+
};
|
|
16027
|
+
Enumerable.unfold = function(seed, func) {
|
|
16028
|
+
func = Utils.createLambda(func);
|
|
16029
|
+
return new Enumerable(function() {
|
|
16030
|
+
var isFirst = true;
|
|
16031
|
+
var value;
|
|
16032
|
+
return new IEnumerator(
|
|
16033
|
+
Functions.Blank,
|
|
16034
|
+
function() {
|
|
16035
|
+
if (isFirst) {
|
|
16036
|
+
isFirst = false;
|
|
16037
|
+
value = seed;
|
|
16038
|
+
return this.yieldReturn(value);
|
|
16039
|
+
}
|
|
16040
|
+
value = func(value);
|
|
16041
|
+
return this.yieldReturn(value);
|
|
16042
|
+
},
|
|
16043
|
+
Functions.Blank
|
|
16044
|
+
);
|
|
16045
|
+
});
|
|
16046
|
+
};
|
|
16047
|
+
Enumerable.defer = function(enumerableFactory) {
|
|
16048
|
+
return new Enumerable(function() {
|
|
16049
|
+
var enumerator;
|
|
16050
|
+
return new IEnumerator(
|
|
16051
|
+
function() {
|
|
16052
|
+
enumerator = Enumerable.from(enumerableFactory()).getEnumerator();
|
|
16053
|
+
},
|
|
16054
|
+
function() {
|
|
16055
|
+
return enumerator.moveNext() ? this.yieldReturn(enumerator.current()) : this.yieldBreak();
|
|
16056
|
+
},
|
|
16057
|
+
function() {
|
|
16058
|
+
Utils.dispose(enumerator);
|
|
16059
|
+
}
|
|
16060
|
+
);
|
|
16061
|
+
});
|
|
16062
|
+
};
|
|
16063
|
+
Enumerable.prototype.traverseBreadthFirst = function(func, resultSelector) {
|
|
16064
|
+
var source = this;
|
|
16065
|
+
func = Utils.createLambda(func);
|
|
16066
|
+
resultSelector = Utils.createLambda(resultSelector);
|
|
16067
|
+
return new Enumerable(function() {
|
|
16068
|
+
var enumerator;
|
|
16069
|
+
var nestLevel = 0;
|
|
16070
|
+
var buffer = [];
|
|
16071
|
+
return new IEnumerator(
|
|
16072
|
+
function() {
|
|
16073
|
+
enumerator = source.getEnumerator();
|
|
16074
|
+
},
|
|
16075
|
+
function() {
|
|
16076
|
+
while (true) {
|
|
16077
|
+
if (enumerator.moveNext()) {
|
|
16078
|
+
buffer.push(enumerator.current());
|
|
16079
|
+
return this.yieldReturn(resultSelector(enumerator.current(), nestLevel));
|
|
16080
|
+
}
|
|
16081
|
+
const next = Enumerable.from(buffer).selectMany(function(x) {
|
|
16082
|
+
return func(x);
|
|
16083
|
+
});
|
|
16084
|
+
if (!next.any()) {
|
|
16085
|
+
return false;
|
|
16086
|
+
} else {
|
|
16087
|
+
nestLevel++;
|
|
16088
|
+
buffer = [];
|
|
16089
|
+
Utils.dispose(enumerator);
|
|
16090
|
+
enumerator = next.getEnumerator();
|
|
16091
|
+
}
|
|
16092
|
+
}
|
|
16093
|
+
},
|
|
16094
|
+
function() {
|
|
16095
|
+
Utils.dispose(enumerator);
|
|
16096
|
+
}
|
|
16097
|
+
);
|
|
16098
|
+
});
|
|
16099
|
+
};
|
|
16100
|
+
Enumerable.prototype.traverseDepthFirst = function(func, resultSelector) {
|
|
16101
|
+
var source = this;
|
|
16102
|
+
func = Utils.createLambda(func);
|
|
16103
|
+
resultSelector = Utils.createLambda(resultSelector);
|
|
16104
|
+
return new Enumerable(function() {
|
|
16105
|
+
var enumeratorStack = [];
|
|
16106
|
+
var enumerator;
|
|
16107
|
+
return new IEnumerator(
|
|
16108
|
+
function() {
|
|
16109
|
+
enumerator = source.getEnumerator();
|
|
16110
|
+
},
|
|
16111
|
+
function() {
|
|
16112
|
+
while (true) {
|
|
16113
|
+
if (enumerator.moveNext()) {
|
|
16114
|
+
const value = resultSelector(enumerator.current(), enumeratorStack.length);
|
|
16115
|
+
enumeratorStack.push(enumerator);
|
|
16116
|
+
enumerator = Enumerable.from(func(enumerator.current())).getEnumerator();
|
|
16117
|
+
return this.yieldReturn(value);
|
|
16118
|
+
}
|
|
16119
|
+
if (enumeratorStack.length <= 0)
|
|
16120
|
+
return false;
|
|
16121
|
+
Utils.dispose(enumerator);
|
|
16122
|
+
enumerator = enumeratorStack.pop();
|
|
16123
|
+
}
|
|
16124
|
+
},
|
|
16125
|
+
function() {
|
|
16126
|
+
try {
|
|
16127
|
+
Utils.dispose(enumerator);
|
|
16128
|
+
} finally {
|
|
16129
|
+
Enumerable.from(enumeratorStack).forEach(function(s) {
|
|
16130
|
+
s.dispose();
|
|
16131
|
+
});
|
|
16132
|
+
}
|
|
16133
|
+
}
|
|
16134
|
+
);
|
|
16135
|
+
});
|
|
16136
|
+
};
|
|
16137
|
+
Enumerable.prototype.flatten = function() {
|
|
16138
|
+
var source = this;
|
|
16139
|
+
return new Enumerable(function() {
|
|
16140
|
+
var enumerator;
|
|
16141
|
+
var middleEnumerator = null;
|
|
16142
|
+
return new IEnumerator(
|
|
16143
|
+
function() {
|
|
16144
|
+
enumerator = source.getEnumerator();
|
|
16145
|
+
},
|
|
16146
|
+
function() {
|
|
16147
|
+
while (true) {
|
|
16148
|
+
if (middleEnumerator != null) {
|
|
16149
|
+
if (middleEnumerator.moveNext()) {
|
|
16150
|
+
return this.yieldReturn(middleEnumerator.current());
|
|
16151
|
+
} else {
|
|
16152
|
+
middleEnumerator = null;
|
|
16153
|
+
}
|
|
16154
|
+
}
|
|
16155
|
+
if (enumerator.moveNext()) {
|
|
16156
|
+
if (enumerator.current() instanceof Array) {
|
|
16157
|
+
Utils.dispose(middleEnumerator);
|
|
16158
|
+
middleEnumerator = Enumerable.from(enumerator.current()).selectMany(Functions.Identity).flatten().getEnumerator();
|
|
16159
|
+
continue;
|
|
16160
|
+
} else {
|
|
16161
|
+
return this.yieldReturn(enumerator.current());
|
|
16162
|
+
}
|
|
16163
|
+
}
|
|
16164
|
+
return false;
|
|
16165
|
+
}
|
|
16166
|
+
},
|
|
16167
|
+
function() {
|
|
16168
|
+
try {
|
|
16169
|
+
Utils.dispose(enumerator);
|
|
16170
|
+
} finally {
|
|
16171
|
+
Utils.dispose(middleEnumerator);
|
|
16172
|
+
}
|
|
16173
|
+
}
|
|
16174
|
+
);
|
|
16175
|
+
});
|
|
16176
|
+
};
|
|
16177
|
+
Enumerable.prototype.pairwise = function(selector) {
|
|
16178
|
+
var source = this;
|
|
16179
|
+
selector = Utils.createLambda(selector);
|
|
16180
|
+
return new Enumerable(function() {
|
|
16181
|
+
var enumerator;
|
|
16182
|
+
return new IEnumerator(
|
|
16183
|
+
function() {
|
|
16184
|
+
enumerator = source.getEnumerator();
|
|
16185
|
+
enumerator.moveNext();
|
|
16186
|
+
},
|
|
16187
|
+
function() {
|
|
16188
|
+
var prev = enumerator.current();
|
|
16189
|
+
return enumerator.moveNext() ? this.yieldReturn(selector(prev, enumerator.current())) : false;
|
|
16190
|
+
},
|
|
16191
|
+
function() {
|
|
16192
|
+
Utils.dispose(enumerator);
|
|
16193
|
+
}
|
|
16194
|
+
);
|
|
16195
|
+
});
|
|
16196
|
+
};
|
|
16197
|
+
Enumerable.prototype.scan = function(seed, func) {
|
|
16198
|
+
var isUseSeed;
|
|
16199
|
+
if (func == null) {
|
|
16200
|
+
func = Utils.createLambda(seed);
|
|
16201
|
+
isUseSeed = false;
|
|
16202
|
+
} else {
|
|
16203
|
+
func = Utils.createLambda(func);
|
|
16204
|
+
isUseSeed = true;
|
|
16205
|
+
}
|
|
16206
|
+
var source = this;
|
|
16207
|
+
return new Enumerable(function() {
|
|
16208
|
+
var enumerator;
|
|
16209
|
+
var value;
|
|
16210
|
+
var isFirst = true;
|
|
16211
|
+
return new IEnumerator(
|
|
16212
|
+
function() {
|
|
16213
|
+
enumerator = source.getEnumerator();
|
|
16214
|
+
},
|
|
16215
|
+
function() {
|
|
16216
|
+
if (isFirst) {
|
|
16217
|
+
isFirst = false;
|
|
16218
|
+
if (!isUseSeed) {
|
|
16219
|
+
if (enumerator.moveNext()) {
|
|
16220
|
+
return this.yieldReturn(value = enumerator.current());
|
|
16221
|
+
}
|
|
16222
|
+
} else {
|
|
16223
|
+
return this.yieldReturn(value = seed);
|
|
16224
|
+
}
|
|
16225
|
+
}
|
|
16226
|
+
return enumerator.moveNext() ? this.yieldReturn(value = func(value, enumerator.current())) : false;
|
|
16227
|
+
},
|
|
16228
|
+
function() {
|
|
16229
|
+
Utils.dispose(enumerator);
|
|
16230
|
+
}
|
|
16231
|
+
);
|
|
16232
|
+
});
|
|
16233
|
+
};
|
|
16234
|
+
Enumerable.prototype.select = function(selector) {
|
|
16235
|
+
selector = Utils.createLambda(selector);
|
|
16236
|
+
if (selector.length <= 1) {
|
|
16237
|
+
return new WhereSelectEnumerable(this, null, selector);
|
|
16238
|
+
} else {
|
|
16239
|
+
var source = this;
|
|
16240
|
+
return new Enumerable(function() {
|
|
16241
|
+
var enumerator;
|
|
16242
|
+
var index = 0;
|
|
16243
|
+
return new IEnumerator(
|
|
16244
|
+
function() {
|
|
16245
|
+
enumerator = source.getEnumerator();
|
|
16246
|
+
},
|
|
16247
|
+
function() {
|
|
16248
|
+
return enumerator.moveNext() ? this.yieldReturn(selector(enumerator.current(), index++)) : false;
|
|
16249
|
+
},
|
|
16250
|
+
function() {
|
|
16251
|
+
Utils.dispose(enumerator);
|
|
16252
|
+
}
|
|
16253
|
+
);
|
|
16254
|
+
});
|
|
16255
|
+
}
|
|
16256
|
+
};
|
|
16257
|
+
Enumerable.prototype.selectMany = function(collectionSelector, resultSelector) {
|
|
16258
|
+
var source = this;
|
|
16259
|
+
collectionSelector = Utils.createLambda(collectionSelector);
|
|
16260
|
+
if (resultSelector == null)
|
|
16261
|
+
resultSelector = function(a, b) {
|
|
16262
|
+
return b;
|
|
16263
|
+
};
|
|
16264
|
+
resultSelector = Utils.createLambda(resultSelector);
|
|
16265
|
+
return new Enumerable(function() {
|
|
16266
|
+
var enumerator;
|
|
16267
|
+
var middleEnumerator = void 0;
|
|
16268
|
+
var index = 0;
|
|
16269
|
+
return new IEnumerator(
|
|
16270
|
+
function() {
|
|
16271
|
+
enumerator = source.getEnumerator();
|
|
16272
|
+
},
|
|
16273
|
+
function() {
|
|
16274
|
+
if (middleEnumerator === void 0) {
|
|
16275
|
+
if (!enumerator.moveNext())
|
|
16276
|
+
return false;
|
|
16277
|
+
}
|
|
16278
|
+
do {
|
|
16279
|
+
if (middleEnumerator == null) {
|
|
16280
|
+
const middleSeq = collectionSelector(enumerator.current(), index++);
|
|
16281
|
+
middleEnumerator = Enumerable.from(middleSeq).getEnumerator();
|
|
16282
|
+
}
|
|
16283
|
+
if (middleEnumerator.moveNext()) {
|
|
16284
|
+
return this.yieldReturn(resultSelector(enumerator.current(), middleEnumerator.current()));
|
|
16285
|
+
}
|
|
16286
|
+
Utils.dispose(middleEnumerator);
|
|
16287
|
+
middleEnumerator = null;
|
|
16288
|
+
} while (enumerator.moveNext());
|
|
16289
|
+
return false;
|
|
16290
|
+
},
|
|
16291
|
+
function() {
|
|
16292
|
+
try {
|
|
16293
|
+
Utils.dispose(enumerator);
|
|
16294
|
+
} finally {
|
|
16295
|
+
Utils.dispose(middleEnumerator);
|
|
16296
|
+
}
|
|
16297
|
+
}
|
|
16298
|
+
);
|
|
16299
|
+
});
|
|
16300
|
+
};
|
|
16301
|
+
Enumerable.prototype.where = function(predicate) {
|
|
16302
|
+
predicate = Utils.createLambda(predicate);
|
|
16303
|
+
if (predicate.length <= 1) {
|
|
16304
|
+
return new WhereEnumerable(this, predicate);
|
|
16305
|
+
} else {
|
|
16306
|
+
var source = this;
|
|
16307
|
+
return new Enumerable(function() {
|
|
16308
|
+
var enumerator;
|
|
16309
|
+
var index = 0;
|
|
16310
|
+
return new IEnumerator(
|
|
16311
|
+
function() {
|
|
16312
|
+
enumerator = source.getEnumerator();
|
|
16313
|
+
},
|
|
16314
|
+
function() {
|
|
16315
|
+
while (enumerator.moveNext()) {
|
|
16316
|
+
if (predicate(enumerator.current(), index++)) {
|
|
16317
|
+
return this.yieldReturn(enumerator.current());
|
|
16318
|
+
}
|
|
16319
|
+
}
|
|
16320
|
+
return false;
|
|
16321
|
+
},
|
|
16322
|
+
function() {
|
|
16323
|
+
Utils.dispose(enumerator);
|
|
16324
|
+
}
|
|
16325
|
+
);
|
|
16326
|
+
});
|
|
16327
|
+
}
|
|
16328
|
+
};
|
|
16329
|
+
Enumerable.prototype.choose = function(selector) {
|
|
16330
|
+
selector = Utils.createLambda(selector);
|
|
16331
|
+
var source = this;
|
|
16332
|
+
return new Enumerable(function() {
|
|
16333
|
+
var enumerator;
|
|
16334
|
+
var index = 0;
|
|
16335
|
+
return new IEnumerator(
|
|
16336
|
+
function() {
|
|
16337
|
+
enumerator = source.getEnumerator();
|
|
16338
|
+
},
|
|
16339
|
+
function() {
|
|
16340
|
+
while (enumerator.moveNext()) {
|
|
16341
|
+
const result = selector(enumerator.current(), index++);
|
|
16342
|
+
if (result != null) {
|
|
16343
|
+
return this.yieldReturn(result);
|
|
16344
|
+
}
|
|
16345
|
+
}
|
|
16346
|
+
return this.yieldBreak();
|
|
16347
|
+
},
|
|
16348
|
+
function() {
|
|
16349
|
+
Utils.dispose(enumerator);
|
|
16350
|
+
}
|
|
16351
|
+
);
|
|
16352
|
+
});
|
|
16353
|
+
};
|
|
16354
|
+
Enumerable.prototype.ofType = function(type) {
|
|
16355
|
+
var typeName;
|
|
16356
|
+
switch (type) {
|
|
16357
|
+
case Number:
|
|
16358
|
+
typeName = Types.Number;
|
|
16359
|
+
break;
|
|
16360
|
+
case String:
|
|
16361
|
+
typeName = Types.String;
|
|
16362
|
+
break;
|
|
16363
|
+
case Boolean:
|
|
16364
|
+
typeName = Types.Boolean;
|
|
16365
|
+
break;
|
|
16366
|
+
case Function:
|
|
16367
|
+
typeName = Types.Function;
|
|
16368
|
+
break;
|
|
16369
|
+
default:
|
|
16370
|
+
typeName = null;
|
|
16371
|
+
break;
|
|
16372
|
+
}
|
|
16373
|
+
return typeName === null ? this.where(function(x) {
|
|
16374
|
+
return x instanceof type;
|
|
16375
|
+
}) : this.where(function(x) {
|
|
16376
|
+
return typeof x === typeName;
|
|
16377
|
+
});
|
|
16378
|
+
};
|
|
16379
|
+
Enumerable.prototype.zip = function() {
|
|
16380
|
+
var args = arguments;
|
|
16381
|
+
var selector = Utils.createLambda(arguments[arguments.length - 1]);
|
|
16382
|
+
var source = this;
|
|
16383
|
+
if (arguments.length == 2) {
|
|
16384
|
+
const second = arguments[0];
|
|
16385
|
+
return new Enumerable(function() {
|
|
16386
|
+
var firstEnumerator;
|
|
16387
|
+
var secondEnumerator;
|
|
16388
|
+
var index = 0;
|
|
16389
|
+
return new IEnumerator(
|
|
16390
|
+
function() {
|
|
16391
|
+
firstEnumerator = source.getEnumerator();
|
|
16392
|
+
secondEnumerator = Enumerable.from(second).getEnumerator();
|
|
16393
|
+
},
|
|
16394
|
+
function() {
|
|
16395
|
+
if (firstEnumerator.moveNext() && secondEnumerator.moveNext()) {
|
|
16396
|
+
return this.yieldReturn(selector(firstEnumerator.current(), secondEnumerator.current(), index++));
|
|
16397
|
+
}
|
|
16398
|
+
return false;
|
|
16399
|
+
},
|
|
16400
|
+
function() {
|
|
16401
|
+
try {
|
|
16402
|
+
Utils.dispose(firstEnumerator);
|
|
16403
|
+
} finally {
|
|
16404
|
+
Utils.dispose(secondEnumerator);
|
|
16405
|
+
}
|
|
16406
|
+
}
|
|
16407
|
+
);
|
|
16408
|
+
});
|
|
16409
|
+
} else {
|
|
16410
|
+
return new Enumerable(function() {
|
|
16411
|
+
var enumerators;
|
|
16412
|
+
var index = 0;
|
|
16413
|
+
return new IEnumerator(
|
|
16414
|
+
function() {
|
|
16415
|
+
var array = Enumerable.make(source).concat(Enumerable.from(args).takeExceptLast().select(Enumerable.from)).select(function(x) {
|
|
16416
|
+
return x.getEnumerator();
|
|
16417
|
+
}).toArray();
|
|
16418
|
+
enumerators = Enumerable.from(array);
|
|
16419
|
+
},
|
|
16420
|
+
function() {
|
|
16421
|
+
if (enumerators.all(function(x) {
|
|
16422
|
+
return x.moveNext();
|
|
16423
|
+
})) {
|
|
16424
|
+
const array = enumerators.select(function(x) {
|
|
16425
|
+
return x.current();
|
|
16426
|
+
}).toArray();
|
|
16427
|
+
array.push(index++);
|
|
16428
|
+
return this.yieldReturn(selector.apply(null, array));
|
|
16429
|
+
} else {
|
|
16430
|
+
return this.yieldBreak();
|
|
16431
|
+
}
|
|
16432
|
+
},
|
|
16433
|
+
function() {
|
|
16434
|
+
Enumerable.from(enumerators).forEach(Utils.dispose);
|
|
16435
|
+
}
|
|
16436
|
+
);
|
|
16437
|
+
});
|
|
16438
|
+
}
|
|
16439
|
+
};
|
|
16440
|
+
Enumerable.prototype.merge = function() {
|
|
16441
|
+
var args = arguments;
|
|
16442
|
+
var source = this;
|
|
16443
|
+
return new Enumerable(function() {
|
|
16444
|
+
var enumerators;
|
|
16445
|
+
var index = -1;
|
|
16446
|
+
return new IEnumerator(
|
|
16447
|
+
function() {
|
|
16448
|
+
enumerators = Enumerable.make(source).concat(Enumerable.from(args).select(Enumerable.from)).select(function(x) {
|
|
16449
|
+
return x.getEnumerator();
|
|
16450
|
+
}).toArray();
|
|
16451
|
+
},
|
|
16452
|
+
function() {
|
|
16453
|
+
while (enumerators.length > 0) {
|
|
16454
|
+
index = index >= enumerators.length - 1 ? 0 : index + 1;
|
|
16455
|
+
const enumerator = enumerators[index];
|
|
16456
|
+
if (enumerator.moveNext()) {
|
|
16457
|
+
return this.yieldReturn(enumerator.current());
|
|
16458
|
+
} else {
|
|
16459
|
+
enumerator.dispose();
|
|
16460
|
+
enumerators.splice(index--, 1);
|
|
16461
|
+
}
|
|
16462
|
+
}
|
|
16463
|
+
return this.yieldBreak();
|
|
16464
|
+
},
|
|
16465
|
+
function() {
|
|
16466
|
+
Enumerable.from(enumerators).forEach(Utils.dispose);
|
|
16467
|
+
}
|
|
16468
|
+
);
|
|
16469
|
+
});
|
|
16470
|
+
};
|
|
16471
|
+
Enumerable.prototype.join = function(inner, outerKeySelector, innerKeySelector, resultSelector, compareSelector) {
|
|
16472
|
+
outerKeySelector = Utils.createLambda(outerKeySelector);
|
|
16473
|
+
innerKeySelector = Utils.createLambda(innerKeySelector);
|
|
16474
|
+
resultSelector = Utils.createLambda(resultSelector);
|
|
16475
|
+
compareSelector = Utils.createLambda(compareSelector);
|
|
16476
|
+
var source = this;
|
|
16477
|
+
return new Enumerable(function() {
|
|
16478
|
+
var outerEnumerator;
|
|
16479
|
+
var lookup;
|
|
16480
|
+
var innerElements = null;
|
|
16481
|
+
var innerCount = 0;
|
|
16482
|
+
return new IEnumerator(
|
|
16483
|
+
function() {
|
|
16484
|
+
outerEnumerator = source.getEnumerator();
|
|
16485
|
+
lookup = Enumerable.from(inner).toLookup(innerKeySelector, Functions.Identity, compareSelector);
|
|
16486
|
+
},
|
|
16487
|
+
function() {
|
|
16488
|
+
while (true) {
|
|
16489
|
+
if (innerElements != null) {
|
|
16490
|
+
let innerElement = innerElements[innerCount++];
|
|
16491
|
+
if (innerElement !== void 0) {
|
|
16492
|
+
return this.yieldReturn(resultSelector(outerEnumerator.current(), innerElement));
|
|
16493
|
+
}
|
|
16494
|
+
innerElement = null;
|
|
16495
|
+
innerCount = 0;
|
|
16496
|
+
}
|
|
16497
|
+
if (outerEnumerator.moveNext()) {
|
|
16498
|
+
const key = outerKeySelector(outerEnumerator.current());
|
|
16499
|
+
innerElements = lookup.get(key).toArray();
|
|
16500
|
+
} else {
|
|
16501
|
+
return false;
|
|
16502
|
+
}
|
|
16503
|
+
}
|
|
16504
|
+
},
|
|
16505
|
+
function() {
|
|
16506
|
+
Utils.dispose(outerEnumerator);
|
|
16507
|
+
}
|
|
16508
|
+
);
|
|
16509
|
+
});
|
|
16510
|
+
};
|
|
16511
|
+
Enumerable.prototype.leftJoin = function(inner, outerKeySelector, innerKeySelector, resultSelector, compareSelector) {
|
|
16512
|
+
outerKeySelector = Utils.createLambda(outerKeySelector);
|
|
16513
|
+
innerKeySelector = Utils.createLambda(innerKeySelector);
|
|
16514
|
+
resultSelector = Utils.createLambda(resultSelector);
|
|
16515
|
+
compareSelector = Utils.createLambda(compareSelector);
|
|
16516
|
+
var source = this;
|
|
16517
|
+
return new Enumerable(function() {
|
|
16518
|
+
var outerEnumerator;
|
|
16519
|
+
var lookup;
|
|
16520
|
+
var innerElements = null;
|
|
16521
|
+
var innerCount = 0;
|
|
16522
|
+
return new IEnumerator(
|
|
16523
|
+
function() {
|
|
16524
|
+
outerEnumerator = source.getEnumerator();
|
|
16525
|
+
lookup = Enumerable.from(inner).toLookup(innerKeySelector, Functions.Identity, compareSelector);
|
|
16526
|
+
},
|
|
16527
|
+
function() {
|
|
16528
|
+
while (true) {
|
|
16529
|
+
if (innerElements != null) {
|
|
16530
|
+
let innerElement = innerElements[innerCount++];
|
|
16531
|
+
if (innerElement !== void 0) {
|
|
16532
|
+
return this.yieldReturn(resultSelector(outerEnumerator.current(), innerElement));
|
|
16533
|
+
}
|
|
16534
|
+
innerElement = null;
|
|
16535
|
+
innerCount = 0;
|
|
16536
|
+
}
|
|
16537
|
+
if (outerEnumerator.moveNext()) {
|
|
16538
|
+
const key = outerKeySelector(outerEnumerator.current());
|
|
16539
|
+
innerElements = lookup.get(key).toArray();
|
|
16540
|
+
if (innerElements == null || innerElements.length == 0) {
|
|
16541
|
+
return this.yieldReturn(resultSelector(outerEnumerator.current(), null));
|
|
16542
|
+
}
|
|
16543
|
+
} else {
|
|
16544
|
+
return false;
|
|
16545
|
+
}
|
|
16546
|
+
}
|
|
16547
|
+
},
|
|
16548
|
+
function() {
|
|
16549
|
+
Utils.dispose(outerEnumerator);
|
|
16550
|
+
}
|
|
16551
|
+
);
|
|
16552
|
+
});
|
|
16553
|
+
};
|
|
16554
|
+
Enumerable.prototype.groupJoin = function(inner, outerKeySelector, innerKeySelector, resultSelector, compareSelector) {
|
|
16555
|
+
outerKeySelector = Utils.createLambda(outerKeySelector);
|
|
16556
|
+
innerKeySelector = Utils.createLambda(innerKeySelector);
|
|
16557
|
+
resultSelector = Utils.createLambda(resultSelector);
|
|
16558
|
+
compareSelector = Utils.createLambda(compareSelector);
|
|
16559
|
+
var source = this;
|
|
16560
|
+
return new Enumerable(function() {
|
|
16561
|
+
var enumerator = source.getEnumerator();
|
|
16562
|
+
var lookup = null;
|
|
16563
|
+
return new IEnumerator(
|
|
16564
|
+
function() {
|
|
16565
|
+
enumerator = source.getEnumerator();
|
|
16566
|
+
lookup = Enumerable.from(inner).toLookup(innerKeySelector, Functions.Identity, compareSelector);
|
|
16567
|
+
},
|
|
16568
|
+
function() {
|
|
16569
|
+
if (enumerator.moveNext()) {
|
|
16570
|
+
const innerElement = lookup.get(outerKeySelector(enumerator.current()));
|
|
16571
|
+
return this.yieldReturn(resultSelector(enumerator.current(), innerElement));
|
|
16572
|
+
}
|
|
16573
|
+
return false;
|
|
16574
|
+
},
|
|
16575
|
+
function() {
|
|
16576
|
+
Utils.dispose(enumerator);
|
|
16577
|
+
}
|
|
16578
|
+
);
|
|
16579
|
+
});
|
|
16580
|
+
};
|
|
16581
|
+
Enumerable.prototype.all = function(predicate) {
|
|
16582
|
+
predicate = Utils.createLambda(predicate);
|
|
16583
|
+
var result = true;
|
|
16584
|
+
this.forEach(function(x) {
|
|
16585
|
+
if (!predicate(x)) {
|
|
16586
|
+
result = false;
|
|
16587
|
+
return false;
|
|
16588
|
+
}
|
|
16589
|
+
});
|
|
16590
|
+
return result;
|
|
16591
|
+
};
|
|
16592
|
+
Enumerable.prototype.any = function(predicate) {
|
|
16593
|
+
predicate = Utils.createLambda(predicate);
|
|
16594
|
+
var enumerator = this.getEnumerator();
|
|
16595
|
+
try {
|
|
16596
|
+
if (arguments.length == 0)
|
|
16597
|
+
return enumerator.moveNext();
|
|
16598
|
+
while (enumerator.moveNext()) {
|
|
16599
|
+
if (predicate(enumerator.current()))
|
|
16600
|
+
return true;
|
|
16601
|
+
}
|
|
16602
|
+
return false;
|
|
16603
|
+
} finally {
|
|
16604
|
+
Utils.dispose(enumerator);
|
|
16605
|
+
}
|
|
16606
|
+
};
|
|
16607
|
+
Enumerable.prototype.isEmpty = function() {
|
|
16608
|
+
return !this.any();
|
|
16609
|
+
};
|
|
16610
|
+
Enumerable.prototype.concat = function() {
|
|
16611
|
+
var source = this;
|
|
16612
|
+
if (arguments.length == 1) {
|
|
16613
|
+
const second = arguments[0];
|
|
16614
|
+
return new Enumerable(function() {
|
|
16615
|
+
var firstEnumerator;
|
|
16616
|
+
var secondEnumerator;
|
|
16617
|
+
return new IEnumerator(
|
|
16618
|
+
function() {
|
|
16619
|
+
firstEnumerator = source.getEnumerator();
|
|
16620
|
+
},
|
|
16621
|
+
function() {
|
|
16622
|
+
if (secondEnumerator == null) {
|
|
16623
|
+
if (firstEnumerator.moveNext())
|
|
16624
|
+
return this.yieldReturn(firstEnumerator.current());
|
|
16625
|
+
secondEnumerator = Enumerable.from(second).getEnumerator();
|
|
16626
|
+
}
|
|
16627
|
+
if (secondEnumerator.moveNext())
|
|
16628
|
+
return this.yieldReturn(secondEnumerator.current());
|
|
16629
|
+
return false;
|
|
16630
|
+
},
|
|
16631
|
+
function() {
|
|
16632
|
+
try {
|
|
16633
|
+
Utils.dispose(firstEnumerator);
|
|
16634
|
+
} finally {
|
|
16635
|
+
Utils.dispose(secondEnumerator);
|
|
16636
|
+
}
|
|
16637
|
+
}
|
|
16638
|
+
);
|
|
16639
|
+
});
|
|
16640
|
+
} else {
|
|
16641
|
+
const args = arguments;
|
|
16642
|
+
return new Enumerable(function() {
|
|
16643
|
+
var enumerators;
|
|
16644
|
+
return new IEnumerator(
|
|
16645
|
+
function() {
|
|
16646
|
+
enumerators = Enumerable.make(source).concat(Enumerable.from(args).select(Enumerable.from)).select(function(x) {
|
|
16647
|
+
return x.getEnumerator();
|
|
16648
|
+
}).toArray();
|
|
16649
|
+
},
|
|
16650
|
+
function() {
|
|
16651
|
+
while (enumerators.length > 0) {
|
|
16652
|
+
const enumerator = enumerators[0];
|
|
16653
|
+
if (enumerator.moveNext()) {
|
|
16654
|
+
return this.yieldReturn(enumerator.current());
|
|
16655
|
+
} else {
|
|
16656
|
+
enumerator.dispose();
|
|
16657
|
+
enumerators.splice(0, 1);
|
|
16658
|
+
}
|
|
16659
|
+
}
|
|
16660
|
+
return this.yieldBreak();
|
|
16661
|
+
},
|
|
16662
|
+
function() {
|
|
16663
|
+
Enumerable.from(enumerators).forEach(Utils.dispose);
|
|
16664
|
+
}
|
|
16665
|
+
);
|
|
16666
|
+
});
|
|
16667
|
+
}
|
|
16668
|
+
};
|
|
16669
|
+
Enumerable.prototype.insert = function(index, second) {
|
|
16670
|
+
var source = this;
|
|
16671
|
+
return new Enumerable(function() {
|
|
16672
|
+
var firstEnumerator;
|
|
16673
|
+
var secondEnumerator;
|
|
16674
|
+
var count = 0;
|
|
16675
|
+
var isEnumerated = false;
|
|
16676
|
+
return new IEnumerator(
|
|
16677
|
+
function() {
|
|
16678
|
+
firstEnumerator = source.getEnumerator();
|
|
16679
|
+
secondEnumerator = Enumerable.from(second).getEnumerator();
|
|
16680
|
+
},
|
|
16681
|
+
function() {
|
|
16682
|
+
if (count == index && secondEnumerator.moveNext()) {
|
|
16683
|
+
isEnumerated = true;
|
|
16684
|
+
return this.yieldReturn(secondEnumerator.current());
|
|
16685
|
+
}
|
|
16686
|
+
if (firstEnumerator.moveNext()) {
|
|
16687
|
+
count++;
|
|
16688
|
+
return this.yieldReturn(firstEnumerator.current());
|
|
16689
|
+
}
|
|
16690
|
+
if (!isEnumerated && secondEnumerator.moveNext()) {
|
|
16691
|
+
return this.yieldReturn(secondEnumerator.current());
|
|
16692
|
+
}
|
|
16693
|
+
return false;
|
|
16694
|
+
},
|
|
16695
|
+
function() {
|
|
16696
|
+
try {
|
|
16697
|
+
Utils.dispose(firstEnumerator);
|
|
16698
|
+
} finally {
|
|
16699
|
+
Utils.dispose(secondEnumerator);
|
|
16700
|
+
}
|
|
16701
|
+
}
|
|
16702
|
+
);
|
|
16703
|
+
});
|
|
16704
|
+
};
|
|
16705
|
+
Enumerable.prototype.alternate = function(alternateValueOrSequence) {
|
|
16706
|
+
var source = this;
|
|
16707
|
+
return new Enumerable(function() {
|
|
16708
|
+
var buffer;
|
|
16709
|
+
var enumerator;
|
|
16710
|
+
var alternateSequence;
|
|
16711
|
+
var alternateEnumerator;
|
|
16712
|
+
return new IEnumerator(
|
|
16713
|
+
function() {
|
|
16714
|
+
if (alternateValueOrSequence instanceof Array || alternateValueOrSequence.getEnumerator != null) {
|
|
16715
|
+
alternateSequence = Enumerable.from(Enumerable.from(alternateValueOrSequence).toArray());
|
|
16716
|
+
} else {
|
|
16717
|
+
alternateSequence = Enumerable.make(alternateValueOrSequence);
|
|
16718
|
+
}
|
|
16719
|
+
enumerator = source.getEnumerator();
|
|
16720
|
+
if (enumerator.moveNext())
|
|
16721
|
+
buffer = enumerator.current();
|
|
16722
|
+
},
|
|
16723
|
+
function() {
|
|
16724
|
+
while (true) {
|
|
16725
|
+
if (alternateEnumerator != null) {
|
|
16726
|
+
if (alternateEnumerator.moveNext()) {
|
|
16727
|
+
return this.yieldReturn(alternateEnumerator.current());
|
|
16728
|
+
} else {
|
|
16729
|
+
alternateEnumerator = null;
|
|
16730
|
+
}
|
|
16731
|
+
}
|
|
16732
|
+
if (buffer == null && enumerator.moveNext()) {
|
|
16733
|
+
buffer = enumerator.current();
|
|
16734
|
+
alternateEnumerator = alternateSequence.getEnumerator();
|
|
16735
|
+
continue;
|
|
16736
|
+
} else if (buffer != null) {
|
|
16737
|
+
const retVal = buffer;
|
|
16738
|
+
buffer = null;
|
|
16739
|
+
return this.yieldReturn(retVal);
|
|
16740
|
+
}
|
|
16741
|
+
return this.yieldBreak();
|
|
16742
|
+
}
|
|
16743
|
+
},
|
|
16744
|
+
function() {
|
|
16745
|
+
try {
|
|
16746
|
+
Utils.dispose(enumerator);
|
|
16747
|
+
} finally {
|
|
16748
|
+
Utils.dispose(alternateEnumerator);
|
|
16749
|
+
}
|
|
16750
|
+
}
|
|
16751
|
+
);
|
|
16752
|
+
});
|
|
16753
|
+
};
|
|
16754
|
+
Enumerable.prototype.contains = function(value, compareSelector) {
|
|
16755
|
+
compareSelector = Utils.createLambda(compareSelector);
|
|
16756
|
+
var enumerator = this.getEnumerator();
|
|
16757
|
+
try {
|
|
16758
|
+
while (enumerator.moveNext()) {
|
|
16759
|
+
if (compareSelector(enumerator.current()) === value)
|
|
16760
|
+
return true;
|
|
16761
|
+
}
|
|
16762
|
+
return false;
|
|
16763
|
+
} finally {
|
|
16764
|
+
Utils.dispose(enumerator);
|
|
16765
|
+
}
|
|
16766
|
+
};
|
|
16767
|
+
Enumerable.prototype.defaultIfEmpty = function(defaultValue) {
|
|
16768
|
+
var source = this;
|
|
16769
|
+
if (defaultValue === void 0)
|
|
16770
|
+
defaultValue = null;
|
|
16771
|
+
return new Enumerable(function() {
|
|
16772
|
+
var enumerator;
|
|
16773
|
+
var isFirst = true;
|
|
16774
|
+
return new IEnumerator(
|
|
16775
|
+
function() {
|
|
16776
|
+
enumerator = source.getEnumerator();
|
|
16777
|
+
},
|
|
16778
|
+
function() {
|
|
16779
|
+
if (enumerator.moveNext()) {
|
|
16780
|
+
isFirst = false;
|
|
16781
|
+
return this.yieldReturn(enumerator.current());
|
|
16782
|
+
} else if (isFirst) {
|
|
16783
|
+
isFirst = false;
|
|
16784
|
+
return this.yieldReturn(defaultValue);
|
|
16785
|
+
}
|
|
16786
|
+
return false;
|
|
16787
|
+
},
|
|
16788
|
+
function() {
|
|
16789
|
+
Utils.dispose(enumerator);
|
|
16790
|
+
}
|
|
16791
|
+
);
|
|
16792
|
+
});
|
|
16793
|
+
};
|
|
16794
|
+
Enumerable.prototype.distinct = function(compareSelector) {
|
|
16795
|
+
return this.except(Enumerable.empty(), compareSelector);
|
|
16796
|
+
};
|
|
16797
|
+
Enumerable.prototype.distinctUntilChanged = function(compareSelector) {
|
|
16798
|
+
compareSelector = Utils.createLambda(compareSelector);
|
|
16799
|
+
var source = this;
|
|
16800
|
+
return new Enumerable(function() {
|
|
16801
|
+
var enumerator;
|
|
16802
|
+
var compareKey;
|
|
16803
|
+
return new IEnumerator(
|
|
16804
|
+
function() {
|
|
16805
|
+
enumerator = source.getEnumerator();
|
|
16806
|
+
},
|
|
16807
|
+
function() {
|
|
16808
|
+
while (enumerator.moveNext()) {
|
|
16809
|
+
const key = compareSelector(enumerator.current());
|
|
16810
|
+
if (compareKey === key) {
|
|
16811
|
+
continue;
|
|
16812
|
+
}
|
|
16813
|
+
compareKey = key;
|
|
16814
|
+
return this.yieldReturn(enumerator.current());
|
|
16815
|
+
}
|
|
16816
|
+
return this.yieldBreak();
|
|
16817
|
+
},
|
|
16818
|
+
function() {
|
|
16819
|
+
Utils.dispose(enumerator);
|
|
16820
|
+
}
|
|
16821
|
+
);
|
|
16822
|
+
});
|
|
16823
|
+
};
|
|
16824
|
+
Enumerable.prototype.except = function(second, compareSelector) {
|
|
16825
|
+
compareSelector = Utils.createLambda(compareSelector);
|
|
16826
|
+
var source = this;
|
|
16827
|
+
return new Enumerable(function() {
|
|
16828
|
+
var enumerator;
|
|
16829
|
+
var keys;
|
|
16830
|
+
return new IEnumerator(
|
|
16831
|
+
function() {
|
|
16832
|
+
enumerator = source.getEnumerator();
|
|
16833
|
+
keys = new Dictionary(compareSelector);
|
|
16834
|
+
Enumerable.from(second).forEach(function(key) {
|
|
16835
|
+
keys.add(key);
|
|
16836
|
+
});
|
|
16837
|
+
},
|
|
16838
|
+
function() {
|
|
16839
|
+
while (enumerator.moveNext()) {
|
|
16840
|
+
const current = enumerator.current();
|
|
16841
|
+
if (!keys.contains(current)) {
|
|
16842
|
+
keys.add(current);
|
|
16843
|
+
return this.yieldReturn(current);
|
|
16844
|
+
}
|
|
16845
|
+
}
|
|
16846
|
+
return false;
|
|
16847
|
+
},
|
|
16848
|
+
function() {
|
|
16849
|
+
Utils.dispose(enumerator);
|
|
16850
|
+
}
|
|
16851
|
+
);
|
|
16852
|
+
});
|
|
16853
|
+
};
|
|
16854
|
+
Enumerable.prototype.intersect = function(second, compareSelector) {
|
|
16855
|
+
compareSelector = Utils.createLambda(compareSelector);
|
|
16856
|
+
var source = this;
|
|
16857
|
+
return new Enumerable(function() {
|
|
16858
|
+
var enumerator;
|
|
16859
|
+
var keys;
|
|
16860
|
+
var outs;
|
|
16861
|
+
return new IEnumerator(
|
|
16862
|
+
function() {
|
|
16863
|
+
enumerator = source.getEnumerator();
|
|
16864
|
+
keys = new Dictionary(compareSelector);
|
|
16865
|
+
Enumerable.from(second).forEach(function(key) {
|
|
16866
|
+
keys.add(key);
|
|
16867
|
+
});
|
|
16868
|
+
outs = new Dictionary(compareSelector);
|
|
16869
|
+
},
|
|
16870
|
+
function() {
|
|
16871
|
+
while (enumerator.moveNext()) {
|
|
16872
|
+
const current = enumerator.current();
|
|
16873
|
+
if (!outs.contains(current) && keys.contains(current)) {
|
|
16874
|
+
outs.add(current);
|
|
16875
|
+
return this.yieldReturn(current);
|
|
16876
|
+
}
|
|
16877
|
+
}
|
|
16878
|
+
return false;
|
|
16879
|
+
},
|
|
16880
|
+
function() {
|
|
16881
|
+
Utils.dispose(enumerator);
|
|
16882
|
+
}
|
|
16883
|
+
);
|
|
16884
|
+
});
|
|
16885
|
+
};
|
|
16886
|
+
Enumerable.prototype.sequenceEqual = function(second, compareSelector) {
|
|
16887
|
+
compareSelector = Utils.createLambda(compareSelector);
|
|
16888
|
+
var firstEnumerator = this.getEnumerator();
|
|
16889
|
+
try {
|
|
16890
|
+
const secondEnumerator = Enumerable.from(second).getEnumerator();
|
|
16891
|
+
try {
|
|
16892
|
+
while (firstEnumerator.moveNext()) {
|
|
16893
|
+
if (!secondEnumerator.moveNext() || compareSelector(firstEnumerator.current()) !== compareSelector(secondEnumerator.current())) {
|
|
16894
|
+
return false;
|
|
16895
|
+
}
|
|
16896
|
+
}
|
|
16897
|
+
if (secondEnumerator.moveNext())
|
|
16898
|
+
return false;
|
|
16899
|
+
return true;
|
|
16900
|
+
} finally {
|
|
16901
|
+
Utils.dispose(secondEnumerator);
|
|
16902
|
+
}
|
|
16903
|
+
} finally {
|
|
16904
|
+
Utils.dispose(firstEnumerator);
|
|
16905
|
+
}
|
|
16906
|
+
};
|
|
16907
|
+
Enumerable.prototype.union = function(second, compareSelector) {
|
|
16908
|
+
compareSelector = Utils.createLambda(compareSelector);
|
|
16909
|
+
var source = this;
|
|
16910
|
+
return new Enumerable(function() {
|
|
16911
|
+
var firstEnumerator;
|
|
16912
|
+
var secondEnumerator;
|
|
16913
|
+
var keys;
|
|
16914
|
+
return new IEnumerator(
|
|
16915
|
+
function() {
|
|
16916
|
+
firstEnumerator = source.getEnumerator();
|
|
16917
|
+
keys = new Dictionary(compareSelector);
|
|
16918
|
+
},
|
|
16919
|
+
function() {
|
|
16920
|
+
var current;
|
|
16921
|
+
if (secondEnumerator === void 0) {
|
|
16922
|
+
while (firstEnumerator.moveNext()) {
|
|
16923
|
+
current = firstEnumerator.current();
|
|
16924
|
+
if (!keys.contains(current)) {
|
|
16925
|
+
keys.add(current);
|
|
16926
|
+
return this.yieldReturn(current);
|
|
16927
|
+
}
|
|
16928
|
+
}
|
|
16929
|
+
secondEnumerator = Enumerable.from(second).getEnumerator();
|
|
16930
|
+
}
|
|
16931
|
+
while (secondEnumerator.moveNext()) {
|
|
16932
|
+
current = secondEnumerator.current();
|
|
16933
|
+
if (!keys.contains(current)) {
|
|
16934
|
+
keys.add(current);
|
|
16935
|
+
return this.yieldReturn(current);
|
|
16936
|
+
}
|
|
16937
|
+
}
|
|
16938
|
+
return false;
|
|
16939
|
+
},
|
|
16940
|
+
function() {
|
|
16941
|
+
try {
|
|
16942
|
+
Utils.dispose(firstEnumerator);
|
|
16943
|
+
} finally {
|
|
16944
|
+
Utils.dispose(secondEnumerator);
|
|
16945
|
+
}
|
|
16946
|
+
}
|
|
16947
|
+
);
|
|
16948
|
+
});
|
|
16949
|
+
};
|
|
16950
|
+
Enumerable.prototype.orderBy = function(keySelector, comparer) {
|
|
16951
|
+
return new OrderedEnumerable(this, keySelector, comparer, false);
|
|
16952
|
+
};
|
|
16953
|
+
Enumerable.prototype.orderByDescending = function(keySelector, comparer) {
|
|
16954
|
+
return new OrderedEnumerable(this, keySelector, comparer, true);
|
|
16955
|
+
};
|
|
16956
|
+
Enumerable.prototype.reverse = function() {
|
|
16957
|
+
var source = this;
|
|
16958
|
+
return new Enumerable(function() {
|
|
16959
|
+
var buffer;
|
|
16960
|
+
var index;
|
|
16961
|
+
return new IEnumerator(
|
|
16962
|
+
function() {
|
|
16963
|
+
buffer = source.toArray();
|
|
16964
|
+
index = buffer.length;
|
|
16965
|
+
},
|
|
16966
|
+
function() {
|
|
16967
|
+
return index > 0 ? this.yieldReturn(buffer[--index]) : false;
|
|
16968
|
+
},
|
|
16969
|
+
Functions.Blank
|
|
16970
|
+
);
|
|
16971
|
+
});
|
|
16972
|
+
};
|
|
16973
|
+
Enumerable.prototype.shuffle = function() {
|
|
16974
|
+
var source = this;
|
|
16975
|
+
return new Enumerable(function() {
|
|
16976
|
+
var buffer;
|
|
16977
|
+
return new IEnumerator(
|
|
16978
|
+
function() {
|
|
16979
|
+
buffer = source.toArray();
|
|
16980
|
+
},
|
|
16981
|
+
function() {
|
|
16982
|
+
if (buffer.length > 0) {
|
|
16983
|
+
const i = Math.floor(Math.random() * buffer.length);
|
|
16984
|
+
return this.yieldReturn(buffer.splice(i, 1)[0]);
|
|
16985
|
+
}
|
|
16986
|
+
return false;
|
|
16987
|
+
},
|
|
16988
|
+
Functions.Blank
|
|
16989
|
+
);
|
|
16990
|
+
});
|
|
16991
|
+
};
|
|
16992
|
+
Enumerable.prototype.weightedSample = function(weightSelector) {
|
|
16993
|
+
weightSelector = Utils.createLambda(weightSelector);
|
|
16994
|
+
var source = this;
|
|
16995
|
+
return new Enumerable(function() {
|
|
16996
|
+
var sortedByBound;
|
|
16997
|
+
var totalWeight = 0;
|
|
16998
|
+
return new IEnumerator(
|
|
16999
|
+
function() {
|
|
17000
|
+
sortedByBound = source.choose(function(x) {
|
|
17001
|
+
var weight = weightSelector(x);
|
|
17002
|
+
if (weight <= 0)
|
|
17003
|
+
return null;
|
|
17004
|
+
totalWeight += weight;
|
|
17005
|
+
return { value: x, bound: totalWeight };
|
|
17006
|
+
}).toArray();
|
|
17007
|
+
},
|
|
17008
|
+
function() {
|
|
17009
|
+
if (sortedByBound.length > 0) {
|
|
17010
|
+
const draw = Math.floor(Math.random() * totalWeight) + 1;
|
|
17011
|
+
let lower = -1;
|
|
17012
|
+
let upper = sortedByBound.length;
|
|
17013
|
+
while (upper - lower > 1) {
|
|
17014
|
+
const index = Math.floor((lower + upper) / 2);
|
|
17015
|
+
if (sortedByBound[index].bound >= draw) {
|
|
17016
|
+
upper = index;
|
|
17017
|
+
} else {
|
|
17018
|
+
lower = index;
|
|
17019
|
+
}
|
|
17020
|
+
}
|
|
17021
|
+
return this.yieldReturn(sortedByBound[upper].value);
|
|
17022
|
+
}
|
|
17023
|
+
return this.yieldBreak();
|
|
17024
|
+
},
|
|
17025
|
+
Functions.Blank
|
|
17026
|
+
);
|
|
17027
|
+
});
|
|
17028
|
+
};
|
|
17029
|
+
Enumerable.prototype.groupBy = function(keySelector, elementSelector, resultSelector, compareSelector) {
|
|
17030
|
+
var source = this;
|
|
17031
|
+
keySelector = Utils.createLambda(keySelector);
|
|
17032
|
+
elementSelector = Utils.createLambda(elementSelector);
|
|
17033
|
+
if (resultSelector != null)
|
|
17034
|
+
resultSelector = Utils.createLambda(resultSelector);
|
|
17035
|
+
compareSelector = Utils.createLambda(compareSelector);
|
|
17036
|
+
return new Enumerable(function() {
|
|
17037
|
+
var enumerator;
|
|
17038
|
+
return new IEnumerator(
|
|
17039
|
+
function() {
|
|
17040
|
+
enumerator = source.toLookup(keySelector, elementSelector, compareSelector).toEnumerable().getEnumerator();
|
|
17041
|
+
},
|
|
17042
|
+
function() {
|
|
17043
|
+
while (enumerator.moveNext()) {
|
|
17044
|
+
return resultSelector == null ? this.yieldReturn(enumerator.current()) : this.yieldReturn(resultSelector(enumerator.current().key(), enumerator.current()));
|
|
17045
|
+
}
|
|
17046
|
+
return false;
|
|
17047
|
+
},
|
|
17048
|
+
function() {
|
|
17049
|
+
Utils.dispose(enumerator);
|
|
17050
|
+
}
|
|
17051
|
+
);
|
|
17052
|
+
});
|
|
17053
|
+
};
|
|
17054
|
+
Enumerable.prototype.partitionBy = function(keySelector, elementSelector, resultSelector, compareSelector) {
|
|
17055
|
+
var source = this;
|
|
17056
|
+
keySelector = Utils.createLambda(keySelector);
|
|
17057
|
+
elementSelector = Utils.createLambda(elementSelector);
|
|
17058
|
+
compareSelector = Utils.createLambda(compareSelector);
|
|
17059
|
+
var hasResultSelector;
|
|
17060
|
+
if (resultSelector == null) {
|
|
17061
|
+
hasResultSelector = false;
|
|
17062
|
+
resultSelector = function(key, group) {
|
|
17063
|
+
return new Grouping(key, group);
|
|
17064
|
+
};
|
|
17065
|
+
} else {
|
|
17066
|
+
hasResultSelector = true;
|
|
17067
|
+
resultSelector = Utils.createLambda(resultSelector);
|
|
17068
|
+
}
|
|
17069
|
+
return new Enumerable(function() {
|
|
17070
|
+
var enumerator;
|
|
17071
|
+
var key;
|
|
17072
|
+
var compareKey;
|
|
17073
|
+
var group = [];
|
|
17074
|
+
return new IEnumerator(
|
|
17075
|
+
function() {
|
|
17076
|
+
enumerator = source.getEnumerator();
|
|
17077
|
+
if (enumerator.moveNext()) {
|
|
17078
|
+
key = keySelector(enumerator.current());
|
|
17079
|
+
compareKey = compareSelector(key);
|
|
17080
|
+
group.push(elementSelector(enumerator.current()));
|
|
17081
|
+
}
|
|
17082
|
+
},
|
|
17083
|
+
function() {
|
|
17084
|
+
var hasNext;
|
|
17085
|
+
while ((hasNext = enumerator.moveNext()) == true) {
|
|
17086
|
+
if (compareKey === compareSelector(keySelector(enumerator.current()))) {
|
|
17087
|
+
group.push(elementSelector(enumerator.current()));
|
|
17088
|
+
} else
|
|
17089
|
+
break;
|
|
17090
|
+
}
|
|
17091
|
+
if (group.length > 0) {
|
|
17092
|
+
const result = hasResultSelector ? resultSelector(key, Enumerable.from(group)) : resultSelector(key, group);
|
|
17093
|
+
if (hasNext) {
|
|
17094
|
+
key = keySelector(enumerator.current());
|
|
17095
|
+
compareKey = compareSelector(key);
|
|
17096
|
+
group = [elementSelector(enumerator.current())];
|
|
17097
|
+
} else
|
|
17098
|
+
group = [];
|
|
17099
|
+
return this.yieldReturn(result);
|
|
17100
|
+
}
|
|
17101
|
+
return false;
|
|
17102
|
+
},
|
|
17103
|
+
function() {
|
|
17104
|
+
Utils.dispose(enumerator);
|
|
17105
|
+
}
|
|
17106
|
+
);
|
|
17107
|
+
});
|
|
17108
|
+
};
|
|
17109
|
+
Enumerable.prototype.buffer = function(count) {
|
|
17110
|
+
var source = this;
|
|
17111
|
+
return new Enumerable(function() {
|
|
17112
|
+
var enumerator;
|
|
17113
|
+
return new IEnumerator(
|
|
17114
|
+
function() {
|
|
17115
|
+
enumerator = source.getEnumerator();
|
|
17116
|
+
},
|
|
17117
|
+
function() {
|
|
17118
|
+
var array = [];
|
|
17119
|
+
var index = 0;
|
|
17120
|
+
while (enumerator.moveNext()) {
|
|
17121
|
+
array.push(enumerator.current());
|
|
17122
|
+
if (++index >= count)
|
|
17123
|
+
return this.yieldReturn(array);
|
|
17124
|
+
}
|
|
17125
|
+
if (array.length > 0)
|
|
17126
|
+
return this.yieldReturn(array);
|
|
17127
|
+
return false;
|
|
17128
|
+
},
|
|
17129
|
+
function() {
|
|
17130
|
+
Utils.dispose(enumerator);
|
|
17131
|
+
}
|
|
17132
|
+
);
|
|
17133
|
+
});
|
|
17134
|
+
};
|
|
17135
|
+
Enumerable.prototype.aggregate = function(seed, func, resultSelector) {
|
|
17136
|
+
resultSelector = Utils.createLambda(resultSelector);
|
|
17137
|
+
return resultSelector(this.scan(seed, func, resultSelector).last());
|
|
17138
|
+
};
|
|
17139
|
+
Enumerable.prototype.average = function(selector) {
|
|
17140
|
+
selector = Utils.createLambda(selector);
|
|
17141
|
+
var sum = 0;
|
|
17142
|
+
var count = 0;
|
|
17143
|
+
this.forEach(function(x) {
|
|
17144
|
+
sum += selector(x);
|
|
17145
|
+
++count;
|
|
17146
|
+
});
|
|
17147
|
+
return sum / count;
|
|
17148
|
+
};
|
|
17149
|
+
Enumerable.prototype.count = function(predicate) {
|
|
17150
|
+
predicate = predicate == null ? Functions.True : Utils.createLambda(predicate);
|
|
17151
|
+
var count = 0;
|
|
17152
|
+
this.forEach(function(x, i) {
|
|
17153
|
+
if (predicate(x, i))
|
|
17154
|
+
++count;
|
|
17155
|
+
});
|
|
17156
|
+
return count;
|
|
17157
|
+
};
|
|
17158
|
+
Enumerable.prototype.max = function(selector) {
|
|
17159
|
+
if (selector == null)
|
|
17160
|
+
selector = Functions.Identity;
|
|
17161
|
+
return this.select(selector).aggregate(function(a, b) {
|
|
17162
|
+
return a > b ? a : b;
|
|
17163
|
+
});
|
|
17164
|
+
};
|
|
17165
|
+
Enumerable.prototype.min = function(selector) {
|
|
17166
|
+
if (selector == null)
|
|
17167
|
+
selector = Functions.Identity;
|
|
17168
|
+
return this.select(selector).aggregate(function(a, b) {
|
|
17169
|
+
return a < b ? a : b;
|
|
17170
|
+
});
|
|
17171
|
+
};
|
|
17172
|
+
Enumerable.prototype.maxBy = function(keySelector) {
|
|
17173
|
+
keySelector = Utils.createLambda(keySelector);
|
|
17174
|
+
return this.aggregate(function(a, b) {
|
|
17175
|
+
return keySelector(a) > keySelector(b) ? a : b;
|
|
17176
|
+
});
|
|
17177
|
+
};
|
|
17178
|
+
Enumerable.prototype.minBy = function(keySelector) {
|
|
17179
|
+
keySelector = Utils.createLambda(keySelector);
|
|
17180
|
+
return this.aggregate(function(a, b) {
|
|
17181
|
+
return keySelector(a) < keySelector(b) ? a : b;
|
|
17182
|
+
});
|
|
17183
|
+
};
|
|
17184
|
+
Enumerable.prototype.sum = function(selector) {
|
|
17185
|
+
if (selector == null)
|
|
17186
|
+
selector = Functions.Identity;
|
|
17187
|
+
return this.select(selector).aggregate(0, function(a, b) {
|
|
17188
|
+
return a + b;
|
|
17189
|
+
});
|
|
17190
|
+
};
|
|
17191
|
+
Enumerable.prototype.elementAt = function(index) {
|
|
17192
|
+
var value;
|
|
17193
|
+
var found = false;
|
|
17194
|
+
this.forEach(function(x, i) {
|
|
17195
|
+
if (i == index) {
|
|
17196
|
+
value = x;
|
|
17197
|
+
found = true;
|
|
17198
|
+
return false;
|
|
17199
|
+
}
|
|
17200
|
+
});
|
|
17201
|
+
if (!found)
|
|
17202
|
+
throw new Error("index is less than 0 or greater than or equal to the number of elements in source.");
|
|
17203
|
+
return value;
|
|
17204
|
+
};
|
|
17205
|
+
Enumerable.prototype.elementAtOrDefault = function(index, defaultValue) {
|
|
17206
|
+
if (defaultValue === void 0)
|
|
17207
|
+
defaultValue = null;
|
|
17208
|
+
var value;
|
|
17209
|
+
var found = false;
|
|
17210
|
+
this.forEach(function(x, i) {
|
|
17211
|
+
if (i == index) {
|
|
17212
|
+
value = x;
|
|
17213
|
+
found = true;
|
|
17214
|
+
return false;
|
|
17215
|
+
}
|
|
17216
|
+
});
|
|
17217
|
+
return !found ? defaultValue : value;
|
|
17218
|
+
};
|
|
17219
|
+
Enumerable.prototype.first = function(predicate) {
|
|
17220
|
+
if (predicate != null)
|
|
17221
|
+
return this.where(predicate).first();
|
|
17222
|
+
var value;
|
|
17223
|
+
var found = false;
|
|
17224
|
+
this.forEach(function(x) {
|
|
17225
|
+
value = x;
|
|
17226
|
+
found = true;
|
|
17227
|
+
return false;
|
|
17228
|
+
});
|
|
17229
|
+
if (!found)
|
|
17230
|
+
throw new Error("first:No element satisfies the condition.");
|
|
17231
|
+
return value;
|
|
17232
|
+
};
|
|
17233
|
+
Enumerable.prototype.firstOrDefault = function(predicate, defaultValue) {
|
|
17234
|
+
if (predicate !== void 0) {
|
|
17235
|
+
if (typeof predicate === Types.Function || typeof Utils.createLambda(predicate) === Types.Function) {
|
|
17236
|
+
return this.where(predicate).firstOrDefault(void 0, defaultValue);
|
|
17237
|
+
}
|
|
17238
|
+
defaultValue = predicate;
|
|
17239
|
+
}
|
|
17240
|
+
var value;
|
|
17241
|
+
var found = false;
|
|
17242
|
+
this.forEach(function(x) {
|
|
17243
|
+
value = x;
|
|
17244
|
+
found = true;
|
|
17245
|
+
return false;
|
|
17246
|
+
});
|
|
17247
|
+
return !found ? defaultValue : value;
|
|
17248
|
+
};
|
|
17249
|
+
Enumerable.prototype.last = function(predicate) {
|
|
17250
|
+
if (predicate != null)
|
|
17251
|
+
return this.where(predicate).last();
|
|
17252
|
+
var value;
|
|
17253
|
+
var found = false;
|
|
17254
|
+
this.forEach(function(x) {
|
|
17255
|
+
found = true;
|
|
17256
|
+
value = x;
|
|
17257
|
+
});
|
|
17258
|
+
if (!found)
|
|
17259
|
+
throw new Error("last:No element satisfies the condition.");
|
|
17260
|
+
return value;
|
|
17261
|
+
};
|
|
17262
|
+
Enumerable.prototype.lastOrDefault = function(predicate, defaultValue) {
|
|
17263
|
+
if (predicate !== void 0) {
|
|
17264
|
+
if (typeof predicate === Types.Function || typeof Utils.createLambda(predicate) === Types.Function) {
|
|
17265
|
+
return this.where(predicate).lastOrDefault(void 0, defaultValue);
|
|
17266
|
+
}
|
|
17267
|
+
defaultValue = predicate;
|
|
17268
|
+
}
|
|
17269
|
+
var value;
|
|
17270
|
+
var found = false;
|
|
17271
|
+
this.forEach(function(x) {
|
|
17272
|
+
found = true;
|
|
17273
|
+
value = x;
|
|
17274
|
+
});
|
|
17275
|
+
return !found ? defaultValue : value;
|
|
17276
|
+
};
|
|
17277
|
+
Enumerable.prototype.single = function(predicate) {
|
|
17278
|
+
if (predicate != null)
|
|
17279
|
+
return this.where(predicate).single();
|
|
17280
|
+
var value;
|
|
17281
|
+
var found = false;
|
|
17282
|
+
this.forEach(function(x) {
|
|
17283
|
+
if (!found) {
|
|
17284
|
+
found = true;
|
|
17285
|
+
value = x;
|
|
17286
|
+
} else
|
|
17287
|
+
throw new Error("single:sequence contains more than one element.");
|
|
17288
|
+
});
|
|
17289
|
+
if (!found)
|
|
17290
|
+
throw new Error("single:No element satisfies the condition.");
|
|
17291
|
+
return value;
|
|
17292
|
+
};
|
|
17293
|
+
Enumerable.prototype.singleOrDefault = function(predicate, defaultValue) {
|
|
17294
|
+
if (defaultValue === void 0)
|
|
17295
|
+
defaultValue = null;
|
|
17296
|
+
if (predicate != null)
|
|
17297
|
+
return this.where(predicate).singleOrDefault(null, defaultValue);
|
|
17298
|
+
var value;
|
|
17299
|
+
var found = false;
|
|
17300
|
+
this.forEach(function(x) {
|
|
17301
|
+
if (!found) {
|
|
17302
|
+
found = true;
|
|
17303
|
+
value = x;
|
|
17304
|
+
} else
|
|
17305
|
+
throw new Error("single:sequence contains more than one element.");
|
|
17306
|
+
});
|
|
17307
|
+
return !found ? defaultValue : value;
|
|
17308
|
+
};
|
|
17309
|
+
Enumerable.prototype.skip = function(count) {
|
|
17310
|
+
var source = this;
|
|
17311
|
+
return new Enumerable(function() {
|
|
17312
|
+
var enumerator;
|
|
17313
|
+
var index = 0;
|
|
17314
|
+
return new IEnumerator(
|
|
17315
|
+
function() {
|
|
17316
|
+
enumerator = source.getEnumerator();
|
|
17317
|
+
while (index++ < count && enumerator.moveNext()) {
|
|
17318
|
+
}
|
|
17319
|
+
},
|
|
17320
|
+
function() {
|
|
17321
|
+
return enumerator.moveNext() ? this.yieldReturn(enumerator.current()) : false;
|
|
17322
|
+
},
|
|
17323
|
+
function() {
|
|
17324
|
+
Utils.dispose(enumerator);
|
|
17325
|
+
}
|
|
17326
|
+
);
|
|
17327
|
+
});
|
|
17328
|
+
};
|
|
17329
|
+
Enumerable.prototype.skipWhile = function(predicate) {
|
|
17330
|
+
predicate = Utils.createLambda(predicate);
|
|
17331
|
+
var source = this;
|
|
17332
|
+
return new Enumerable(function() {
|
|
17333
|
+
var enumerator;
|
|
17334
|
+
var index = 0;
|
|
17335
|
+
var isSkipEnd = false;
|
|
17336
|
+
return new IEnumerator(
|
|
17337
|
+
function() {
|
|
17338
|
+
enumerator = source.getEnumerator();
|
|
17339
|
+
},
|
|
17340
|
+
function() {
|
|
17341
|
+
while (!isSkipEnd) {
|
|
17342
|
+
if (enumerator.moveNext()) {
|
|
17343
|
+
if (!predicate(enumerator.current(), index++)) {
|
|
17344
|
+
isSkipEnd = true;
|
|
17345
|
+
return this.yieldReturn(enumerator.current());
|
|
17346
|
+
}
|
|
17347
|
+
continue;
|
|
17348
|
+
} else
|
|
17349
|
+
return false;
|
|
17350
|
+
}
|
|
17351
|
+
return enumerator.moveNext() ? this.yieldReturn(enumerator.current()) : false;
|
|
17352
|
+
},
|
|
17353
|
+
function() {
|
|
17354
|
+
Utils.dispose(enumerator);
|
|
17355
|
+
}
|
|
17356
|
+
);
|
|
17357
|
+
});
|
|
17358
|
+
};
|
|
17359
|
+
Enumerable.prototype.take = function(count) {
|
|
17360
|
+
var source = this;
|
|
17361
|
+
return new Enumerable(function() {
|
|
17362
|
+
var enumerator;
|
|
17363
|
+
var index = 0;
|
|
17364
|
+
return new IEnumerator(
|
|
17365
|
+
function() {
|
|
17366
|
+
enumerator = source.getEnumerator();
|
|
17367
|
+
},
|
|
17368
|
+
function() {
|
|
17369
|
+
return index++ < count && enumerator.moveNext() ? this.yieldReturn(enumerator.current()) : false;
|
|
17370
|
+
},
|
|
17371
|
+
function() {
|
|
17372
|
+
Utils.dispose(enumerator);
|
|
17373
|
+
}
|
|
17374
|
+
);
|
|
17375
|
+
});
|
|
17376
|
+
};
|
|
17377
|
+
Enumerable.prototype.takeWhile = function(predicate) {
|
|
17378
|
+
predicate = Utils.createLambda(predicate);
|
|
17379
|
+
var source = this;
|
|
17380
|
+
return new Enumerable(function() {
|
|
17381
|
+
var enumerator;
|
|
17382
|
+
var index = 0;
|
|
17383
|
+
return new IEnumerator(
|
|
17384
|
+
function() {
|
|
17385
|
+
enumerator = source.getEnumerator();
|
|
17386
|
+
},
|
|
17387
|
+
function() {
|
|
17388
|
+
return enumerator.moveNext() && predicate(enumerator.current(), index++) ? this.yieldReturn(enumerator.current()) : false;
|
|
17389
|
+
},
|
|
17390
|
+
function() {
|
|
17391
|
+
Utils.dispose(enumerator);
|
|
17392
|
+
}
|
|
17393
|
+
);
|
|
17394
|
+
});
|
|
17395
|
+
};
|
|
17396
|
+
Enumerable.prototype.takeExceptLast = function(count) {
|
|
17397
|
+
if (count == null)
|
|
17398
|
+
count = 1;
|
|
17399
|
+
var source = this;
|
|
17400
|
+
return new Enumerable(function() {
|
|
17401
|
+
if (count <= 0)
|
|
17402
|
+
return source.getEnumerator();
|
|
17403
|
+
var enumerator;
|
|
17404
|
+
var q = [];
|
|
17405
|
+
return new IEnumerator(
|
|
17406
|
+
function() {
|
|
17407
|
+
enumerator = source.getEnumerator();
|
|
17408
|
+
},
|
|
17409
|
+
function() {
|
|
17410
|
+
while (enumerator.moveNext()) {
|
|
17411
|
+
if (q.length == count) {
|
|
17412
|
+
q.push(enumerator.current());
|
|
17413
|
+
return this.yieldReturn(q.shift());
|
|
17414
|
+
}
|
|
17415
|
+
q.push(enumerator.current());
|
|
17416
|
+
}
|
|
17417
|
+
return false;
|
|
17418
|
+
},
|
|
17419
|
+
function() {
|
|
17420
|
+
Utils.dispose(enumerator);
|
|
17421
|
+
}
|
|
17422
|
+
);
|
|
17423
|
+
});
|
|
17424
|
+
};
|
|
17425
|
+
Enumerable.prototype.takeFromLast = function(count) {
|
|
17426
|
+
if (count <= 0 || count == null)
|
|
17427
|
+
return Enumerable.empty();
|
|
17428
|
+
var source = this;
|
|
17429
|
+
return new Enumerable(function() {
|
|
17430
|
+
var sourceEnumerator;
|
|
17431
|
+
var enumerator;
|
|
17432
|
+
var q = [];
|
|
17433
|
+
return new IEnumerator(
|
|
17434
|
+
function() {
|
|
17435
|
+
sourceEnumerator = source.getEnumerator();
|
|
17436
|
+
},
|
|
17437
|
+
function() {
|
|
17438
|
+
while (sourceEnumerator.moveNext()) {
|
|
17439
|
+
if (q.length == count)
|
|
17440
|
+
q.shift();
|
|
17441
|
+
q.push(sourceEnumerator.current());
|
|
17442
|
+
}
|
|
17443
|
+
if (enumerator == null) {
|
|
17444
|
+
enumerator = Enumerable.from(q).getEnumerator();
|
|
17445
|
+
}
|
|
17446
|
+
return enumerator.moveNext() ? this.yieldReturn(enumerator.current()) : false;
|
|
17447
|
+
},
|
|
17448
|
+
function() {
|
|
17449
|
+
Utils.dispose(enumerator);
|
|
17450
|
+
}
|
|
17451
|
+
);
|
|
17452
|
+
});
|
|
17453
|
+
};
|
|
17454
|
+
Enumerable.prototype.indexOf = function(item) {
|
|
17455
|
+
var found = null;
|
|
17456
|
+
if (typeof item === Types.Function) {
|
|
17457
|
+
this.forEach(function(x, i) {
|
|
17458
|
+
if (item(x, i)) {
|
|
17459
|
+
found = i;
|
|
17460
|
+
return false;
|
|
17461
|
+
}
|
|
17462
|
+
});
|
|
17463
|
+
} else {
|
|
17464
|
+
this.forEach(function(x, i) {
|
|
17465
|
+
if (x === item) {
|
|
17466
|
+
found = i;
|
|
17467
|
+
return false;
|
|
17468
|
+
}
|
|
17469
|
+
});
|
|
17470
|
+
}
|
|
17471
|
+
return found !== null ? found : -1;
|
|
17472
|
+
};
|
|
17473
|
+
Enumerable.prototype.lastIndexOf = function(item) {
|
|
17474
|
+
var result = -1;
|
|
17475
|
+
if (typeof item === Types.Function) {
|
|
17476
|
+
this.forEach(function(x, i) {
|
|
17477
|
+
if (item(x, i))
|
|
17478
|
+
result = i;
|
|
17479
|
+
});
|
|
17480
|
+
} else {
|
|
17481
|
+
this.forEach(function(x, i) {
|
|
17482
|
+
if (x === item)
|
|
17483
|
+
result = i;
|
|
17484
|
+
});
|
|
17485
|
+
}
|
|
17486
|
+
return result;
|
|
17487
|
+
};
|
|
17488
|
+
Enumerable.prototype.cast = function() {
|
|
17489
|
+
return this;
|
|
17490
|
+
};
|
|
17491
|
+
Enumerable.prototype.asEnumerable = function() {
|
|
17492
|
+
return Enumerable.from(this);
|
|
17493
|
+
};
|
|
17494
|
+
Enumerable.prototype.toArray = function() {
|
|
17495
|
+
var array = [];
|
|
17496
|
+
this.forEach(function(x) {
|
|
17497
|
+
array.push(x);
|
|
17498
|
+
});
|
|
17499
|
+
return array;
|
|
17500
|
+
};
|
|
17501
|
+
Enumerable.prototype.toLookup = function(keySelector, elementSelector, compareSelector) {
|
|
17502
|
+
keySelector = Utils.createLambda(keySelector);
|
|
17503
|
+
elementSelector = Utils.createLambda(elementSelector);
|
|
17504
|
+
compareSelector = Utils.createLambda(compareSelector);
|
|
17505
|
+
var dict = new Dictionary(compareSelector);
|
|
17506
|
+
this.forEach(function(x) {
|
|
17507
|
+
var key = keySelector(x);
|
|
17508
|
+
var element = elementSelector(x);
|
|
17509
|
+
var array = dict.get(key);
|
|
17510
|
+
if (array !== void 0)
|
|
17511
|
+
array.push(element);
|
|
17512
|
+
else
|
|
17513
|
+
dict.add(key, [element]);
|
|
17514
|
+
});
|
|
17515
|
+
return new Lookup(dict);
|
|
17516
|
+
};
|
|
17517
|
+
Enumerable.prototype.toObject = function(keySelector, elementSelector) {
|
|
17518
|
+
keySelector = Utils.createLambda(keySelector);
|
|
17519
|
+
elementSelector = Utils.createLambda(elementSelector);
|
|
17520
|
+
var obj = {};
|
|
17521
|
+
this.forEach(function(x) {
|
|
17522
|
+
obj[keySelector(x)] = elementSelector(x);
|
|
17523
|
+
});
|
|
17524
|
+
return obj;
|
|
17525
|
+
};
|
|
17526
|
+
Enumerable.prototype.toDictionary = function(keySelector, elementSelector, compareSelector) {
|
|
17527
|
+
keySelector = Utils.createLambda(keySelector);
|
|
17528
|
+
elementSelector = Utils.createLambda(elementSelector);
|
|
17529
|
+
compareSelector = Utils.createLambda(compareSelector);
|
|
17530
|
+
var dict = new Dictionary(compareSelector);
|
|
17531
|
+
this.forEach(function(x) {
|
|
17532
|
+
dict.add(keySelector(x), elementSelector(x));
|
|
17533
|
+
});
|
|
17534
|
+
return dict;
|
|
17535
|
+
};
|
|
17536
|
+
Enumerable.prototype.toJSONString = function(replacer, space) {
|
|
17537
|
+
if (typeof JSON === Types.Undefined || JSON.stringify == null) {
|
|
17538
|
+
throw new Error("toJSONString can't find JSON.stringify. This works native JSON support Browser or include json2.js");
|
|
17539
|
+
}
|
|
17540
|
+
return JSON.stringify(this.toArray(), replacer, space);
|
|
17541
|
+
};
|
|
17542
|
+
Enumerable.prototype.toJoinedString = function(separator, selector) {
|
|
17543
|
+
if (separator == null)
|
|
17544
|
+
separator = "";
|
|
17545
|
+
if (selector == null)
|
|
17546
|
+
selector = Functions.Identity;
|
|
17547
|
+
return this.select(selector).toArray().join(separator);
|
|
17548
|
+
};
|
|
17549
|
+
Enumerable.prototype.doAction = function(action) {
|
|
17550
|
+
var source = this;
|
|
17551
|
+
action = Utils.createLambda(action);
|
|
17552
|
+
return new Enumerable(function() {
|
|
17553
|
+
var enumerator;
|
|
17554
|
+
var index = 0;
|
|
17555
|
+
return new IEnumerator(
|
|
17556
|
+
function() {
|
|
17557
|
+
enumerator = source.getEnumerator();
|
|
17558
|
+
},
|
|
17559
|
+
function() {
|
|
17560
|
+
if (enumerator.moveNext()) {
|
|
17561
|
+
action(enumerator.current(), index++);
|
|
17562
|
+
return this.yieldReturn(enumerator.current());
|
|
17563
|
+
}
|
|
17564
|
+
return false;
|
|
17565
|
+
},
|
|
17566
|
+
function() {
|
|
17567
|
+
Utils.dispose(enumerator);
|
|
17568
|
+
}
|
|
17569
|
+
);
|
|
17570
|
+
});
|
|
17571
|
+
};
|
|
17572
|
+
Enumerable.prototype.forEach = function(action) {
|
|
17573
|
+
action = Utils.createLambda(action);
|
|
17574
|
+
var index = 0;
|
|
17575
|
+
var enumerator = this.getEnumerator();
|
|
17576
|
+
try {
|
|
17577
|
+
while (enumerator.moveNext()) {
|
|
17578
|
+
if (action(enumerator.current(), index++) === false)
|
|
17579
|
+
break;
|
|
17580
|
+
}
|
|
17581
|
+
} finally {
|
|
17582
|
+
Utils.dispose(enumerator);
|
|
17583
|
+
}
|
|
17584
|
+
};
|
|
17585
|
+
Enumerable.prototype.force = function() {
|
|
17586
|
+
var enumerator = this.getEnumerator();
|
|
17587
|
+
try {
|
|
17588
|
+
while (enumerator.moveNext()) {
|
|
17589
|
+
}
|
|
17590
|
+
} finally {
|
|
17591
|
+
Utils.dispose(enumerator);
|
|
17592
|
+
}
|
|
17593
|
+
};
|
|
17594
|
+
Enumerable.prototype.letBind = function(func) {
|
|
17595
|
+
func = Utils.createLambda(func);
|
|
17596
|
+
var source = this;
|
|
17597
|
+
return new Enumerable(function() {
|
|
17598
|
+
var enumerator;
|
|
17599
|
+
return new IEnumerator(
|
|
17600
|
+
function() {
|
|
17601
|
+
enumerator = Enumerable.from(func(source)).getEnumerator();
|
|
17602
|
+
},
|
|
17603
|
+
function() {
|
|
17604
|
+
return enumerator.moveNext() ? this.yieldReturn(enumerator.current()) : false;
|
|
17605
|
+
},
|
|
17606
|
+
function() {
|
|
17607
|
+
Utils.dispose(enumerator);
|
|
17608
|
+
}
|
|
17609
|
+
);
|
|
17610
|
+
});
|
|
17611
|
+
};
|
|
17612
|
+
Enumerable.prototype.share = function() {
|
|
17613
|
+
var source = this;
|
|
17614
|
+
var sharedEnumerator;
|
|
17615
|
+
var disposed = false;
|
|
17616
|
+
return new DisposableEnumerable(function() {
|
|
17617
|
+
return new IEnumerator(
|
|
17618
|
+
function() {
|
|
17619
|
+
if (sharedEnumerator == null) {
|
|
17620
|
+
sharedEnumerator = source.getEnumerator();
|
|
17621
|
+
}
|
|
17622
|
+
},
|
|
17623
|
+
function() {
|
|
17624
|
+
if (disposed)
|
|
17625
|
+
throw new Error("enumerator is disposed");
|
|
17626
|
+
return sharedEnumerator.moveNext() ? this.yieldReturn(sharedEnumerator.current()) : false;
|
|
17627
|
+
},
|
|
17628
|
+
Functions.Blank
|
|
17629
|
+
);
|
|
17630
|
+
}, function() {
|
|
17631
|
+
disposed = true;
|
|
17632
|
+
Utils.dispose(sharedEnumerator);
|
|
17633
|
+
});
|
|
17634
|
+
};
|
|
17635
|
+
Enumerable.prototype.memoize = function() {
|
|
17636
|
+
var source = this;
|
|
17637
|
+
var cache;
|
|
17638
|
+
var enumerator;
|
|
17639
|
+
var disposed = false;
|
|
17640
|
+
return new DisposableEnumerable(function() {
|
|
17641
|
+
var index = -1;
|
|
17642
|
+
return new IEnumerator(
|
|
17643
|
+
function() {
|
|
17644
|
+
if (enumerator == null) {
|
|
17645
|
+
enumerator = source.getEnumerator();
|
|
17646
|
+
cache = [];
|
|
17647
|
+
}
|
|
17648
|
+
},
|
|
17649
|
+
function() {
|
|
17650
|
+
if (disposed)
|
|
17651
|
+
throw new Error("enumerator is disposed");
|
|
17652
|
+
index++;
|
|
17653
|
+
if (cache.length <= index) {
|
|
17654
|
+
return enumerator.moveNext() ? this.yieldReturn(cache[index] = enumerator.current()) : false;
|
|
17655
|
+
}
|
|
17656
|
+
return this.yieldReturn(cache[index]);
|
|
17657
|
+
},
|
|
17658
|
+
Functions.Blank
|
|
17659
|
+
);
|
|
17660
|
+
}, function() {
|
|
17661
|
+
disposed = true;
|
|
17662
|
+
Utils.dispose(enumerator);
|
|
17663
|
+
cache = null;
|
|
17664
|
+
});
|
|
17665
|
+
};
|
|
17666
|
+
if (Utils.hasNativeIteratorSupport()) {
|
|
17667
|
+
Enumerable.prototype[Symbol.iterator] = function() {
|
|
17668
|
+
return {
|
|
17669
|
+
enumerator: this.getEnumerator(),
|
|
17670
|
+
next: function() {
|
|
17671
|
+
if (this.enumerator.moveNext()) {
|
|
17672
|
+
return {
|
|
17673
|
+
done: false,
|
|
17674
|
+
value: this.enumerator.current()
|
|
17675
|
+
};
|
|
17676
|
+
} else {
|
|
17677
|
+
return { done: true };
|
|
17678
|
+
}
|
|
17679
|
+
}
|
|
17680
|
+
};
|
|
17681
|
+
};
|
|
17682
|
+
}
|
|
17683
|
+
Enumerable.prototype.catchError = function(handler) {
|
|
17684
|
+
handler = Utils.createLambda(handler);
|
|
17685
|
+
var source = this;
|
|
17686
|
+
return new Enumerable(function() {
|
|
17687
|
+
var enumerator;
|
|
17688
|
+
return new IEnumerator(
|
|
17689
|
+
function() {
|
|
17690
|
+
enumerator = source.getEnumerator();
|
|
17691
|
+
},
|
|
17692
|
+
function() {
|
|
17693
|
+
try {
|
|
17694
|
+
return enumerator.moveNext() ? this.yieldReturn(enumerator.current()) : false;
|
|
17695
|
+
} catch (e) {
|
|
17696
|
+
handler(e);
|
|
17697
|
+
return false;
|
|
17698
|
+
}
|
|
17699
|
+
},
|
|
17700
|
+
function() {
|
|
17701
|
+
Utils.dispose(enumerator);
|
|
17702
|
+
}
|
|
17703
|
+
);
|
|
17704
|
+
});
|
|
17705
|
+
};
|
|
17706
|
+
Enumerable.prototype.finallyAction = function(finallyAction) {
|
|
17707
|
+
finallyAction = Utils.createLambda(finallyAction);
|
|
17708
|
+
var source = this;
|
|
17709
|
+
return new Enumerable(function() {
|
|
17710
|
+
var enumerator;
|
|
17711
|
+
return new IEnumerator(
|
|
17712
|
+
function() {
|
|
17713
|
+
enumerator = source.getEnumerator();
|
|
17714
|
+
},
|
|
17715
|
+
function() {
|
|
17716
|
+
return enumerator.moveNext() ? this.yieldReturn(enumerator.current()) : false;
|
|
17717
|
+
},
|
|
17718
|
+
function() {
|
|
17719
|
+
try {
|
|
17720
|
+
Utils.dispose(enumerator);
|
|
17721
|
+
} finally {
|
|
17722
|
+
finallyAction();
|
|
17723
|
+
}
|
|
17724
|
+
}
|
|
17725
|
+
);
|
|
17726
|
+
});
|
|
17727
|
+
};
|
|
17728
|
+
Enumerable.prototype.log = function(selector) {
|
|
17729
|
+
selector = Utils.createLambda(selector);
|
|
17730
|
+
return this.doAction(function(item) {
|
|
17731
|
+
if (typeof console !== Types.Undefined) {
|
|
17732
|
+
console.log(selector(item));
|
|
17733
|
+
}
|
|
17734
|
+
});
|
|
17735
|
+
};
|
|
17736
|
+
Enumerable.prototype.trace = function(message, selector) {
|
|
17737
|
+
if (message == null)
|
|
17738
|
+
message = "Trace";
|
|
17739
|
+
selector = Utils.createLambda(selector);
|
|
17740
|
+
return this.doAction(function(item) {
|
|
17741
|
+
if (typeof console !== Types.Undefined) {
|
|
17742
|
+
console.log(message, selector(item));
|
|
17743
|
+
}
|
|
17744
|
+
});
|
|
17745
|
+
};
|
|
17746
|
+
var OrderedEnumerable = function(source, keySelector, comparer, descending, parent) {
|
|
17747
|
+
this.source = source;
|
|
17748
|
+
this.keySelector = Utils.createLambda(keySelector);
|
|
17749
|
+
this.descending = descending;
|
|
17750
|
+
this.parent = parent;
|
|
17751
|
+
if (comparer)
|
|
17752
|
+
this.comparer = Utils.createLambda(comparer);
|
|
17753
|
+
};
|
|
17754
|
+
OrderedEnumerable.prototype = new Enumerable();
|
|
17755
|
+
OrderedEnumerable.prototype.createOrderedEnumerable = function(keySelector, comparer, descending) {
|
|
17756
|
+
return new OrderedEnumerable(this.source, keySelector, comparer, descending, this);
|
|
17757
|
+
};
|
|
17758
|
+
OrderedEnumerable.prototype.thenBy = function(keySelector, comparer) {
|
|
17759
|
+
return this.createOrderedEnumerable(keySelector, comparer, false);
|
|
17760
|
+
};
|
|
17761
|
+
OrderedEnumerable.prototype.thenByDescending = function(keySelector, comparer) {
|
|
17762
|
+
return this.createOrderedEnumerable(keySelector, comparer, true);
|
|
17763
|
+
};
|
|
17764
|
+
OrderedEnumerable.prototype.getEnumerator = function() {
|
|
17765
|
+
var self2 = this;
|
|
17766
|
+
var buffer;
|
|
17767
|
+
var indexes;
|
|
17768
|
+
var index = 0;
|
|
17769
|
+
return new IEnumerator(
|
|
17770
|
+
function() {
|
|
17771
|
+
buffer = [];
|
|
17772
|
+
indexes = [];
|
|
17773
|
+
self2.source.forEach(function(item, index2) {
|
|
17774
|
+
buffer.push(item);
|
|
17775
|
+
indexes.push(index2);
|
|
17776
|
+
});
|
|
17777
|
+
var sortContext = SortContext.create(self2, null);
|
|
17778
|
+
sortContext.GenerateKeys(buffer);
|
|
17779
|
+
indexes.sort(function(a, b) {
|
|
17780
|
+
return sortContext.compare(a, b);
|
|
17781
|
+
});
|
|
17782
|
+
},
|
|
17783
|
+
function() {
|
|
17784
|
+
return index < indexes.length ? this.yieldReturn(buffer[indexes[index++]]) : false;
|
|
17785
|
+
},
|
|
17786
|
+
Functions.Blank
|
|
17787
|
+
);
|
|
17788
|
+
};
|
|
17789
|
+
var SortContext = function(keySelector, comparer, descending, child) {
|
|
17790
|
+
this.keySelector = keySelector;
|
|
17791
|
+
this.descending = descending;
|
|
17792
|
+
this.child = child;
|
|
17793
|
+
this.comparer = comparer;
|
|
17794
|
+
this.keys = null;
|
|
17795
|
+
};
|
|
17796
|
+
SortContext.create = function(orderedEnumerable, currentContext) {
|
|
17797
|
+
var context = new SortContext(
|
|
17798
|
+
orderedEnumerable.keySelector,
|
|
17799
|
+
orderedEnumerable.comparer,
|
|
17800
|
+
orderedEnumerable.descending,
|
|
17801
|
+
currentContext
|
|
17802
|
+
);
|
|
17803
|
+
if (orderedEnumerable.parent != null)
|
|
17804
|
+
return SortContext.create(orderedEnumerable.parent, context);
|
|
17805
|
+
return context;
|
|
17806
|
+
};
|
|
17807
|
+
SortContext.prototype.GenerateKeys = function(source) {
|
|
17808
|
+
var len = source.length;
|
|
17809
|
+
var keySelector = this.keySelector;
|
|
17810
|
+
var keys = new Array(len);
|
|
17811
|
+
for (let i = 0; i < len; i++)
|
|
17812
|
+
keys[i] = keySelector(source[i]);
|
|
17813
|
+
this.keys = keys;
|
|
17814
|
+
if (this.child != null)
|
|
17815
|
+
this.child.GenerateKeys(source);
|
|
17816
|
+
};
|
|
17817
|
+
SortContext.prototype.compare = function(index1, index2) {
|
|
17818
|
+
var comparison = this.comparer ? this.comparer(this.keys[index1], this.keys[index2]) : Utils.compare(this.keys[index1], this.keys[index2]);
|
|
17819
|
+
if (comparison == 0) {
|
|
17820
|
+
if (this.child != null)
|
|
17821
|
+
return this.child.compare(index1, index2);
|
|
17822
|
+
return Utils.compare(index1, index2);
|
|
17823
|
+
}
|
|
17824
|
+
return this.descending ? -comparison : comparison;
|
|
17825
|
+
};
|
|
17826
|
+
var DisposableEnumerable = function(getEnumerator, dispose) {
|
|
17827
|
+
this.dispose = dispose;
|
|
17828
|
+
Enumerable.call(this, getEnumerator);
|
|
17829
|
+
};
|
|
17830
|
+
DisposableEnumerable.prototype = new Enumerable();
|
|
17831
|
+
var ArrayEnumerable = function(source) {
|
|
17832
|
+
this.getSource = function() {
|
|
17833
|
+
return source;
|
|
17834
|
+
};
|
|
17835
|
+
};
|
|
17836
|
+
ArrayEnumerable.prototype = new Enumerable();
|
|
17837
|
+
ArrayEnumerable.prototype.any = function(predicate) {
|
|
17838
|
+
return predicate == null ? this.getSource().length > 0 : Enumerable.prototype.any.apply(this, arguments);
|
|
17839
|
+
};
|
|
17840
|
+
ArrayEnumerable.prototype.count = function(predicate) {
|
|
17841
|
+
return predicate == null ? this.getSource().length : Enumerable.prototype.count.apply(this, arguments);
|
|
17842
|
+
};
|
|
17843
|
+
ArrayEnumerable.prototype.elementAt = function(index) {
|
|
17844
|
+
var source = this.getSource();
|
|
17845
|
+
return 0 <= index && index < source.length ? source[index] : Enumerable.prototype.elementAt.apply(this, arguments);
|
|
17846
|
+
};
|
|
17847
|
+
ArrayEnumerable.prototype.elementAtOrDefault = function(index, defaultValue) {
|
|
17848
|
+
if (defaultValue === void 0)
|
|
17849
|
+
defaultValue = null;
|
|
17850
|
+
var source = this.getSource();
|
|
17851
|
+
return 0 <= index && index < source.length ? source[index] : defaultValue;
|
|
17852
|
+
};
|
|
17853
|
+
ArrayEnumerable.prototype.first = function(predicate) {
|
|
17854
|
+
var source = this.getSource();
|
|
17855
|
+
return predicate == null && source.length > 0 ? source[0] : Enumerable.prototype.first.apply(this, arguments);
|
|
17856
|
+
};
|
|
17857
|
+
ArrayEnumerable.prototype.firstOrDefault = function(predicate, defaultValue) {
|
|
17858
|
+
if (predicate !== void 0) {
|
|
17859
|
+
return Enumerable.prototype.firstOrDefault.apply(this, arguments);
|
|
17860
|
+
}
|
|
17861
|
+
defaultValue = predicate;
|
|
17862
|
+
var source = this.getSource();
|
|
17863
|
+
return source.length > 0 ? source[0] : defaultValue;
|
|
17864
|
+
};
|
|
17865
|
+
ArrayEnumerable.prototype.last = function(predicate) {
|
|
17866
|
+
var source = this.getSource();
|
|
17867
|
+
return predicate == null && source.length > 0 ? source[source.length - 1] : Enumerable.prototype.last.apply(this, arguments);
|
|
17868
|
+
};
|
|
17869
|
+
ArrayEnumerable.prototype.lastOrDefault = function(predicate, defaultValue) {
|
|
17870
|
+
if (predicate !== void 0) {
|
|
17871
|
+
return Enumerable.prototype.lastOrDefault.apply(this, arguments);
|
|
17872
|
+
}
|
|
17873
|
+
defaultValue = predicate;
|
|
17874
|
+
var source = this.getSource();
|
|
17875
|
+
return source.length > 0 ? source[source.length - 1] : defaultValue;
|
|
17876
|
+
};
|
|
17877
|
+
ArrayEnumerable.prototype.skip = function(count) {
|
|
17878
|
+
var source = this.getSource();
|
|
17879
|
+
return new Enumerable(function() {
|
|
17880
|
+
var index;
|
|
17881
|
+
return new IEnumerator(
|
|
17882
|
+
function() {
|
|
17883
|
+
index = count < 0 ? 0 : count;
|
|
17884
|
+
},
|
|
17885
|
+
function() {
|
|
17886
|
+
return index < source.length ? this.yieldReturn(source[index++]) : false;
|
|
17887
|
+
},
|
|
17888
|
+
Functions.Blank
|
|
17889
|
+
);
|
|
17890
|
+
});
|
|
17891
|
+
};
|
|
17892
|
+
ArrayEnumerable.prototype.takeExceptLast = function(count) {
|
|
17893
|
+
if (count == null)
|
|
17894
|
+
count = 1;
|
|
17895
|
+
return this.take(this.getSource().length - count);
|
|
17896
|
+
};
|
|
17897
|
+
ArrayEnumerable.prototype.takeFromLast = function(count) {
|
|
17898
|
+
return this.skip(this.getSource().length - count);
|
|
17899
|
+
};
|
|
17900
|
+
ArrayEnumerable.prototype.reverse = function() {
|
|
17901
|
+
var source = this.getSource();
|
|
17902
|
+
return new Enumerable(function() {
|
|
17903
|
+
var index;
|
|
17904
|
+
return new IEnumerator(
|
|
17905
|
+
function() {
|
|
17906
|
+
index = source.length;
|
|
17907
|
+
},
|
|
17908
|
+
function() {
|
|
17909
|
+
return index > 0 ? this.yieldReturn(source[--index]) : false;
|
|
17910
|
+
},
|
|
17911
|
+
Functions.Blank
|
|
17912
|
+
);
|
|
17913
|
+
});
|
|
17914
|
+
};
|
|
17915
|
+
ArrayEnumerable.prototype.sequenceEqual = function(second, compareSelector) {
|
|
17916
|
+
if ((second instanceof ArrayEnumerable || second instanceof Array) && compareSelector == null && Enumerable.from(second).count() != this.count()) {
|
|
17917
|
+
return false;
|
|
17918
|
+
}
|
|
17919
|
+
return Enumerable.prototype.sequenceEqual.apply(this, arguments);
|
|
17920
|
+
};
|
|
17921
|
+
ArrayEnumerable.prototype.toJoinedString = function(separator, selector) {
|
|
17922
|
+
var source = this.getSource();
|
|
17923
|
+
if (selector != null || !(source instanceof Array)) {
|
|
17924
|
+
return Enumerable.prototype.toJoinedString.apply(this, arguments);
|
|
17925
|
+
}
|
|
17926
|
+
if (separator == null)
|
|
17927
|
+
separator = "";
|
|
17928
|
+
return source.join(separator);
|
|
17929
|
+
};
|
|
17930
|
+
ArrayEnumerable.prototype.getEnumerator = function() {
|
|
17931
|
+
var source = this.getSource();
|
|
17932
|
+
var index = -1;
|
|
17933
|
+
return {
|
|
17934
|
+
current: function() {
|
|
17935
|
+
return source[index];
|
|
17936
|
+
},
|
|
17937
|
+
moveNext: function() {
|
|
17938
|
+
return ++index < source.length;
|
|
17939
|
+
},
|
|
17940
|
+
dispose: Functions.Blank
|
|
17941
|
+
};
|
|
17942
|
+
};
|
|
17943
|
+
var WhereEnumerable = function(source, predicate) {
|
|
17944
|
+
this.prevSource = source;
|
|
17945
|
+
this.prevPredicate = predicate;
|
|
17946
|
+
};
|
|
17947
|
+
WhereEnumerable.prototype = new Enumerable();
|
|
17948
|
+
WhereEnumerable.prototype.where = function(predicate) {
|
|
17949
|
+
predicate = Utils.createLambda(predicate);
|
|
17950
|
+
if (predicate.length <= 1) {
|
|
17951
|
+
const prevPredicate = this.prevPredicate;
|
|
17952
|
+
const composedPredicate = function(x) {
|
|
17953
|
+
return prevPredicate(x) && predicate(x);
|
|
17954
|
+
};
|
|
17955
|
+
return new WhereEnumerable(this.prevSource, composedPredicate);
|
|
17956
|
+
} else {
|
|
17957
|
+
return Enumerable.prototype.where.call(this, predicate);
|
|
17958
|
+
}
|
|
17959
|
+
};
|
|
17960
|
+
WhereEnumerable.prototype.select = function(selector) {
|
|
17961
|
+
selector = Utils.createLambda(selector);
|
|
17962
|
+
return selector.length <= 1 ? new WhereSelectEnumerable(this.prevSource, this.prevPredicate, selector) : Enumerable.prototype.select.call(this, selector);
|
|
17963
|
+
};
|
|
17964
|
+
WhereEnumerable.prototype.getEnumerator = function() {
|
|
17965
|
+
var predicate = this.prevPredicate;
|
|
17966
|
+
var source = this.prevSource;
|
|
17967
|
+
var enumerator;
|
|
17968
|
+
return new IEnumerator(
|
|
17969
|
+
function() {
|
|
17970
|
+
enumerator = source.getEnumerator();
|
|
17971
|
+
},
|
|
17972
|
+
function() {
|
|
17973
|
+
while (enumerator.moveNext()) {
|
|
17974
|
+
if (predicate(enumerator.current())) {
|
|
17975
|
+
return this.yieldReturn(enumerator.current());
|
|
17976
|
+
}
|
|
17977
|
+
}
|
|
17978
|
+
return false;
|
|
17979
|
+
},
|
|
17980
|
+
function() {
|
|
17981
|
+
Utils.dispose(enumerator);
|
|
17982
|
+
}
|
|
17983
|
+
);
|
|
17984
|
+
};
|
|
17985
|
+
var WhereSelectEnumerable = function(source, predicate, selector) {
|
|
17986
|
+
this.prevSource = source;
|
|
17987
|
+
this.prevPredicate = predicate;
|
|
17988
|
+
this.prevSelector = selector;
|
|
17989
|
+
};
|
|
17990
|
+
WhereSelectEnumerable.prototype = new Enumerable();
|
|
17991
|
+
WhereSelectEnumerable.prototype.where = function(predicate) {
|
|
17992
|
+
predicate = Utils.createLambda(predicate);
|
|
17993
|
+
return predicate.length <= 1 ? new WhereEnumerable(this, predicate) : Enumerable.prototype.where.call(this, predicate);
|
|
17994
|
+
};
|
|
17995
|
+
WhereSelectEnumerable.prototype.select = function(selector) {
|
|
17996
|
+
selector = Utils.createLambda(selector);
|
|
17997
|
+
if (selector.length <= 1) {
|
|
17998
|
+
const prevSelector = this.prevSelector;
|
|
17999
|
+
const composedSelector = function(x) {
|
|
18000
|
+
return selector(prevSelector(x));
|
|
18001
|
+
};
|
|
18002
|
+
return new WhereSelectEnumerable(this.prevSource, this.prevPredicate, composedSelector);
|
|
18003
|
+
} else {
|
|
18004
|
+
return Enumerable.prototype.select.call(this, selector);
|
|
18005
|
+
}
|
|
18006
|
+
};
|
|
18007
|
+
WhereSelectEnumerable.prototype.getEnumerator = function() {
|
|
18008
|
+
var predicate = this.prevPredicate;
|
|
18009
|
+
var selector = this.prevSelector;
|
|
18010
|
+
var source = this.prevSource;
|
|
18011
|
+
var enumerator;
|
|
18012
|
+
return new IEnumerator(
|
|
18013
|
+
function() {
|
|
18014
|
+
enumerator = source.getEnumerator();
|
|
18015
|
+
},
|
|
18016
|
+
function() {
|
|
18017
|
+
while (enumerator.moveNext()) {
|
|
18018
|
+
if (predicate == null || predicate(enumerator.current())) {
|
|
18019
|
+
return this.yieldReturn(selector(enumerator.current()));
|
|
18020
|
+
}
|
|
18021
|
+
}
|
|
18022
|
+
return false;
|
|
18023
|
+
},
|
|
18024
|
+
function() {
|
|
18025
|
+
Utils.dispose(enumerator);
|
|
18026
|
+
}
|
|
18027
|
+
);
|
|
18028
|
+
};
|
|
18029
|
+
var Dictionary = function() {
|
|
18030
|
+
var callHasOwnProperty = function(target, key) {
|
|
18031
|
+
return Object.prototype.hasOwnProperty.call(target, key);
|
|
18032
|
+
};
|
|
18033
|
+
var computeHashCode = function(obj) {
|
|
18034
|
+
if (obj === null)
|
|
18035
|
+
return "null";
|
|
18036
|
+
if (obj === void 0)
|
|
18037
|
+
return "undefined";
|
|
18038
|
+
return typeof obj.toString === Types.Function ? obj.toString() : Object.prototype.toString.call(obj);
|
|
18039
|
+
};
|
|
18040
|
+
var HashEntry = function(key, value) {
|
|
18041
|
+
this.key = key;
|
|
18042
|
+
this.value = value;
|
|
18043
|
+
this.prev = null;
|
|
18044
|
+
this.next = null;
|
|
18045
|
+
};
|
|
18046
|
+
var EntryList = function() {
|
|
18047
|
+
this.first = null;
|
|
18048
|
+
this.last = null;
|
|
18049
|
+
};
|
|
18050
|
+
EntryList.prototype = {
|
|
18051
|
+
addLast: function(entry) {
|
|
18052
|
+
if (this.last != null) {
|
|
18053
|
+
this.last.next = entry;
|
|
18054
|
+
entry.prev = this.last;
|
|
18055
|
+
this.last = entry;
|
|
18056
|
+
} else
|
|
18057
|
+
this.first = this.last = entry;
|
|
18058
|
+
},
|
|
18059
|
+
replace: function(entry, newEntry) {
|
|
18060
|
+
if (entry.prev != null) {
|
|
18061
|
+
entry.prev.next = newEntry;
|
|
18062
|
+
newEntry.prev = entry.prev;
|
|
18063
|
+
} else
|
|
18064
|
+
this.first = newEntry;
|
|
18065
|
+
if (entry.next != null) {
|
|
18066
|
+
entry.next.prev = newEntry;
|
|
18067
|
+
newEntry.next = entry.next;
|
|
18068
|
+
} else
|
|
18069
|
+
this.last = newEntry;
|
|
18070
|
+
},
|
|
18071
|
+
remove: function(entry) {
|
|
18072
|
+
if (entry.prev != null)
|
|
18073
|
+
entry.prev.next = entry.next;
|
|
18074
|
+
else
|
|
18075
|
+
this.first = entry.next;
|
|
18076
|
+
if (entry.next != null)
|
|
18077
|
+
entry.next.prev = entry.prev;
|
|
18078
|
+
else
|
|
18079
|
+
this.last = entry.prev;
|
|
18080
|
+
}
|
|
18081
|
+
};
|
|
18082
|
+
var Dictionary2 = function(compareSelector) {
|
|
18083
|
+
this.countField = 0;
|
|
18084
|
+
this.entryList = new EntryList();
|
|
18085
|
+
this.buckets = {};
|
|
18086
|
+
this.compareSelector = compareSelector == null ? Functions.Identity : compareSelector;
|
|
18087
|
+
};
|
|
18088
|
+
Dictionary2.prototype = {
|
|
18089
|
+
add: function(key, value) {
|
|
18090
|
+
var compareKey = this.compareSelector(key);
|
|
18091
|
+
var hash = computeHashCode(compareKey);
|
|
18092
|
+
var entry = new HashEntry(key, value);
|
|
18093
|
+
if (callHasOwnProperty(this.buckets, hash)) {
|
|
18094
|
+
const array = this.buckets[hash];
|
|
18095
|
+
for (let i = 0; i < array.length; i++) {
|
|
18096
|
+
if (this.compareSelector(array[i].key) === compareKey) {
|
|
18097
|
+
this.entryList.replace(array[i], entry);
|
|
18098
|
+
array[i] = entry;
|
|
18099
|
+
return;
|
|
18100
|
+
}
|
|
18101
|
+
}
|
|
18102
|
+
array.push(entry);
|
|
18103
|
+
} else {
|
|
18104
|
+
this.buckets[hash] = [entry];
|
|
18105
|
+
}
|
|
18106
|
+
this.countField++;
|
|
18107
|
+
this.entryList.addLast(entry);
|
|
18108
|
+
},
|
|
18109
|
+
get: function(key) {
|
|
18110
|
+
var compareKey = this.compareSelector(key);
|
|
18111
|
+
var hash = computeHashCode(compareKey);
|
|
18112
|
+
if (!callHasOwnProperty(this.buckets, hash))
|
|
18113
|
+
return void 0;
|
|
18114
|
+
var array = this.buckets[hash];
|
|
18115
|
+
for (let i = 0; i < array.length; i++) {
|
|
18116
|
+
const entry = array[i];
|
|
18117
|
+
if (this.compareSelector(entry.key) === compareKey)
|
|
18118
|
+
return entry.value;
|
|
18119
|
+
}
|
|
18120
|
+
return void 0;
|
|
18121
|
+
},
|
|
18122
|
+
set: function(key, value) {
|
|
18123
|
+
var compareKey = this.compareSelector(key);
|
|
18124
|
+
var hash = computeHashCode(compareKey);
|
|
18125
|
+
if (callHasOwnProperty(this.buckets, hash)) {
|
|
18126
|
+
const array = this.buckets[hash];
|
|
18127
|
+
for (let i = 0; i < array.length; i++) {
|
|
18128
|
+
if (this.compareSelector(array[i].key) === compareKey) {
|
|
18129
|
+
const newEntry = new HashEntry(key, value);
|
|
18130
|
+
this.entryList.replace(array[i], newEntry);
|
|
18131
|
+
array[i] = newEntry;
|
|
18132
|
+
return true;
|
|
18133
|
+
}
|
|
18134
|
+
}
|
|
18135
|
+
}
|
|
18136
|
+
return false;
|
|
18137
|
+
},
|
|
18138
|
+
contains: function(key) {
|
|
18139
|
+
var compareKey = this.compareSelector(key);
|
|
18140
|
+
var hash = computeHashCode(compareKey);
|
|
18141
|
+
if (!callHasOwnProperty(this.buckets, hash))
|
|
18142
|
+
return false;
|
|
18143
|
+
var array = this.buckets[hash];
|
|
18144
|
+
for (let i = 0; i < array.length; i++) {
|
|
18145
|
+
if (this.compareSelector(array[i].key) === compareKey)
|
|
18146
|
+
return true;
|
|
18147
|
+
}
|
|
18148
|
+
return false;
|
|
18149
|
+
},
|
|
18150
|
+
clear: function() {
|
|
18151
|
+
this.countField = 0;
|
|
18152
|
+
this.buckets = {};
|
|
18153
|
+
this.entryList = new EntryList();
|
|
18154
|
+
},
|
|
18155
|
+
remove: function(key) {
|
|
18156
|
+
var compareKey = this.compareSelector(key);
|
|
18157
|
+
var hash = computeHashCode(compareKey);
|
|
18158
|
+
if (!callHasOwnProperty(this.buckets, hash))
|
|
18159
|
+
return;
|
|
18160
|
+
var array = this.buckets[hash];
|
|
18161
|
+
for (let i = 0; i < array.length; i++) {
|
|
18162
|
+
if (this.compareSelector(array[i].key) === compareKey) {
|
|
18163
|
+
this.entryList.remove(array[i]);
|
|
18164
|
+
array.splice(i, 1);
|
|
18165
|
+
if (array.length == 0)
|
|
18166
|
+
delete this.buckets[hash];
|
|
18167
|
+
this.countField--;
|
|
18168
|
+
return;
|
|
18169
|
+
}
|
|
18170
|
+
}
|
|
18171
|
+
},
|
|
18172
|
+
count: function() {
|
|
18173
|
+
return this.countField;
|
|
18174
|
+
},
|
|
18175
|
+
toEnumerable: function() {
|
|
18176
|
+
var self2 = this;
|
|
18177
|
+
return new Enumerable(function() {
|
|
18178
|
+
var currentEntry;
|
|
18179
|
+
return new IEnumerator(
|
|
18180
|
+
function() {
|
|
18181
|
+
currentEntry = self2.entryList.first;
|
|
18182
|
+
},
|
|
18183
|
+
function() {
|
|
18184
|
+
if (currentEntry != null) {
|
|
18185
|
+
const result = { key: currentEntry.key, value: currentEntry.value };
|
|
18186
|
+
currentEntry = currentEntry.next;
|
|
18187
|
+
return this.yieldReturn(result);
|
|
18188
|
+
}
|
|
18189
|
+
return false;
|
|
18190
|
+
},
|
|
18191
|
+
Functions.Blank
|
|
18192
|
+
);
|
|
18193
|
+
});
|
|
18194
|
+
}
|
|
18195
|
+
};
|
|
18196
|
+
return Dictionary2;
|
|
18197
|
+
}();
|
|
18198
|
+
var Lookup = function(dictionary) {
|
|
18199
|
+
this.count = function() {
|
|
18200
|
+
return dictionary.count();
|
|
18201
|
+
};
|
|
18202
|
+
this.get = function(key) {
|
|
18203
|
+
return Enumerable.from(dictionary.get(key));
|
|
18204
|
+
};
|
|
18205
|
+
this.contains = function(key) {
|
|
18206
|
+
return dictionary.contains(key);
|
|
18207
|
+
};
|
|
18208
|
+
this.toEnumerable = function() {
|
|
18209
|
+
return dictionary.toEnumerable().select(function(kvp) {
|
|
18210
|
+
return new Grouping(kvp.key, kvp.value);
|
|
18211
|
+
});
|
|
18212
|
+
};
|
|
18213
|
+
};
|
|
18214
|
+
var Grouping = function(groupKey, elements) {
|
|
18215
|
+
this.key = function() {
|
|
18216
|
+
return groupKey;
|
|
18217
|
+
};
|
|
18218
|
+
ArrayEnumerable.call(this, elements);
|
|
18219
|
+
};
|
|
18220
|
+
Grouping.prototype = new ArrayEnumerable();
|
|
15550
18221
|
const propDefine$1 = {
|
|
15551
18222
|
// modelValue:{
|
|
15552
18223
|
// // 平台Id
|
|
@@ -15606,7 +18277,7 @@ class StructureTypeSelectInstance extends BaseInstance {
|
|
|
15606
18277
|
this.activeTypeItem.value = item;
|
|
15607
18278
|
}
|
|
15608
18279
|
if (this.structrueTypeLevGroup.value.find((e) => e["level"] == level)) {
|
|
15609
|
-
let index =
|
|
18280
|
+
let index = Enumerable.from(this.structrueTypeLevGroup.value).indexOf((e) => e["level"] == level);
|
|
15610
18281
|
this.structrueTypeLevGroup.value[index] = item;
|
|
15611
18282
|
this.structrueTypeLevGroup.value.splice(index + 1, this.structrueTypeLevGroup.value.length);
|
|
15612
18283
|
} else {
|
|
@@ -15628,14 +18299,14 @@ class StructureTypeSelectInstance extends BaseInstance {
|
|
|
15628
18299
|
if (state) {
|
|
15629
18300
|
this.StructureTypeCheckData.value.push(item);
|
|
15630
18301
|
} else {
|
|
15631
|
-
let index =
|
|
18302
|
+
let index = Enumerable.from(this.StructureTypeCheckData.value).indexOf((e) => e["value"] == item.value);
|
|
15632
18303
|
this.StructureTypeCheckData.value.splice(index, 1);
|
|
15633
18304
|
}
|
|
15634
18305
|
this.doSelectedAfterFun();
|
|
15635
18306
|
});
|
|
15636
18307
|
__publicField(this, "removeStructureType", (item) => {
|
|
15637
18308
|
this.changeTreeItem(this.StructureTypeData.value, item.value, "checked", false);
|
|
15638
|
-
let index =
|
|
18309
|
+
let index = Enumerable.from(this.StructureTypeCheckData.value).indexOf((e) => e["value"] == item.value);
|
|
15639
18310
|
this.StructureTypeCheckData.value.splice(index, 1);
|
|
15640
18311
|
});
|
|
15641
18312
|
__publicField(this, "poptipVisChange", () => {
|
|
@@ -15678,7 +18349,7 @@ class StructureTypeSelectInstance extends BaseInstance {
|
|
|
15678
18349
|
this.searchTypeList.value = [];
|
|
15679
18350
|
});
|
|
15680
18351
|
__publicField(this, "toCheckSearchType", (item, state) => {
|
|
15681
|
-
let index =
|
|
18352
|
+
let index = Enumerable.from(this.StructureTypeCheckData.value).indexOf((e) => e["value"] == item.value);
|
|
15682
18353
|
if (state || index >= 0) {
|
|
15683
18354
|
this.StructureTypeCheckData.value.push({ value: item.Id, label: item.NodeName, parentPath: item.parentPath });
|
|
15684
18355
|
this.changeTreeItem(this.StructureTypeData.value, item.Id, "checked", true);
|
|
@@ -15764,7 +18435,7 @@ class StructureTypeSelectInstance extends BaseInstance {
|
|
|
15764
18435
|
obj.value = e[value];
|
|
15765
18436
|
obj.label = e[label];
|
|
15766
18437
|
obj.parentPath = JSON.parse(JSON.stringify(parentPath2));
|
|
15767
|
-
let index =
|
|
18438
|
+
let index = Enumerable.from(this.StructureTypeDataAll).indexOf((x) => x["Id"] == obj.value);
|
|
15768
18439
|
this.StructureTypeDataAll[index].parentPath = obj.parentPath;
|
|
15769
18440
|
obj.level = obj.parentPath.length + 1;
|
|
15770
18441
|
if (this.props.multiple) {
|
|
@@ -16139,7 +18810,7 @@ class StructureSelectInstance extends BaseInstance {
|
|
|
16139
18810
|
*/
|
|
16140
18811
|
__publicField(this, "removeStructureInstance", (item) => {
|
|
16141
18812
|
item.checked = false;
|
|
16142
|
-
let index =
|
|
18813
|
+
let index = Enumerable.from(this.StructureInstanceCheckData.value).indexOf((e) => e["Id"] == item.Id);
|
|
16143
18814
|
this.StructureInstanceCheckData.value.splice(index, 1);
|
|
16144
18815
|
this.treeChStateChange(this.StructureInstanceData.value);
|
|
16145
18816
|
this.doSelectedAfterFun();
|
|
@@ -16153,7 +18824,7 @@ class StructureSelectInstance extends BaseInstance {
|
|
|
16153
18824
|
*/
|
|
16154
18825
|
async loadNodeTypeAndUnitData() {
|
|
16155
18826
|
let res = this.utilities.parseApiResult(await this.structureInstanceApi.getEntities(new QueryWrapper().select(["Id", "NodeTypeName", "NodeType", "NodeName"]).eq("PId", 0)));
|
|
16156
|
-
this.TypeGroupData.value =
|
|
18827
|
+
this.TypeGroupData.value = Enumerable.from(res).groupBy((e) => e["NodeTypeName"]).select((e) => {
|
|
16157
18828
|
return {
|
|
16158
18829
|
NodeTypeName: e.key(),
|
|
16159
18830
|
UnitData: e.getSource()
|