Skip to content

Commit 14a7c1d

Browse files
committedJan 15, 2024
fix yield and order no returns
1 parent 0e226bb commit 14a7c1d

File tree

3 files changed

+20
-25
lines changed

3 files changed

+20
-25
lines changed
 

‎index.ts

+16-23
Original file line numberDiff line numberDiff line change
@@ -710,7 +710,7 @@ declare interface Generator<T> {
710710
}
711711

712712
* append(element : T) : IEnumerable<T> {
713-
for (const item of this) yield item
713+
yield * this
714714
yield element
715715
}
716716

@@ -731,8 +731,8 @@ declare interface Generator<T> {
731731
}
732732

733733
* concat(source : IEnumerable<T>) : IEnumerable<T> {
734-
for (const item of this) yield item
735-
for (const item of source) yield item
734+
yield * this
735+
yield * source
736736
}
737737

738738
contains(value : T) : boolean;
@@ -763,7 +763,7 @@ declare interface Generator<T> {
763763
stack.push(item)
764764
}
765765
}
766-
for (const item of stack) yield item
766+
yield * stack
767767
}
768768

769769
distinctBy<TKey>(keySelector : (item : T) => TKey) : IEnumerable<T>;
@@ -778,7 +778,7 @@ declare interface Generator<T> {
778778
stack.push(item)
779779
}
780780
}
781-
for (const item of stack) yield item
781+
yield * stack
782782
}
783783

784784
elementAt(index : number) : T {
@@ -995,9 +995,7 @@ declare interface Generator<T> {
995995
order() : IEnumerable<T>;
996996
order(comparer : (current : T, exist : T) => number) : IEnumerable<T>;
997997
* order(comparer? : (current : T, exist : T) => number) : IEnumerable<T> {
998-
comparer ??= (
999-
left,
1000-
right) => left as any - (right as any)
998+
comparer ??= (left, right) => left as any - (right as any)
1001999
const stack = []
10021000
for (const item of this) {
10031001
const index = stack.findIndex((x : any) => comparer(item, x) <= 0)
@@ -1007,6 +1005,7 @@ declare interface Generator<T> {
10071005
stack.splice(index, 0, item)
10081006
}
10091007
}
1008+
yield * stack
10101009
}
10111010

10121011
orderBy<TKey>(keySelector : (item : T) => TKey) : IEnumerable<T>;
@@ -1028,7 +1027,7 @@ declare interface Generator<T> {
10281027
stack.splice(index, 0, item)
10291028
}
10301029
}
1031-
for (const item of stack) yield item
1030+
yield * stack
10321031
}
10331032

10341033
orderByDescending<TKey>(keySelector : (item : T) => TKey) : IEnumerable<T>;
@@ -1050,7 +1049,7 @@ declare interface Generator<T> {
10501049
stack.splice(index, 0, item)
10511050
}
10521051
}
1053-
for (const item of stack) yield item
1052+
yield * stack
10541053
}
10551054

10561055
orderDescending() : IEnumerable<T>;
@@ -1068,12 +1067,12 @@ declare interface Generator<T> {
10681067
stack.splice(index, 0, item)
10691068
}
10701069
}
1071-
for (const item of stack) yield item
1070+
yield * stack
10721071
}
10731072

10741073
* prepend(element : T) : IEnumerable<T> {
10751074
yield element;
1076-
for (const item of this) yield item
1075+
yield * this
10771076
}
10781077

10791078
* reverse() : IEnumerable<T> {
@@ -1206,9 +1205,7 @@ declare interface Generator<T> {
12061205
stack.shift()
12071206
}
12081207
}
1209-
for (const item of stack) {
1210-
yield item
1211-
}
1208+
yield * stack
12121209
}
12131210

12141211
takeWhile(predicate : (item : T) => boolean) : IEnumerable<T>;
@@ -1260,9 +1257,7 @@ declare interface Generator<T> {
12601257
union.push(item)
12611258
}
12621259
}
1263-
for (const item of union) {
1264-
yield item
1265-
}
1260+
yield * union
12661261
}
12671262

12681263
* unionBy<TKey>(
@@ -1282,9 +1277,7 @@ declare interface Generator<T> {
12821277
union.push(item)
12831278
}
12841279
}
1285-
for (const item of union) {
1286-
yield item
1287-
}
1280+
yield * union
12881281
}
12891282

12901283

@@ -1301,7 +1294,7 @@ declare interface Generator<T> {
13011294

13021295
class PartialArrayLike<T> extends Enumerable<T> {
13031296
* asEnumerable() : IEnumerable<T> {
1304-
for (const item of this) yield item;
1297+
yield * this
13051298
}
13061299
}
13071300

@@ -1319,7 +1312,7 @@ declare interface Generator<T> {
13191312
}
13201313

13211314
* asEnumerable() : IEnumerable<T> {
1322-
for (const item of this) yield item;
1315+
yield * this
13231316
}
13241317

13251318
clear() : void {

‎tsconfig.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
"target" : "es6",
44
"lib" : [
55
"dom",
6-
"es6"
6+
"es6",
7+
"es2020.bigint"
78
],
89
"moduleResolution" : "Node",
910
"module" : "ES6"

‎types/index.d.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,8 @@ declare interface Array<T> {
611611
removeAt(index : number) : T | undefined
612612
}
613613

614-
declare class List<T> extends Array<T> {}
614+
declare class List<T> extends Array<T> {
615+
}
615616

616617
declare interface Map<K, V> extends IEnumerable<[K, V]> {
617618

0 commit comments

Comments
 (0)
Please sign in to comment.