@fable-org/fable-library-ts 1.10.0 → 2.0.0-beta.2

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/Seq2.ts CHANGED
@@ -1,129 +1,129 @@
1
- import { toList, toArray, map, filter, delay } from "./Seq.js";
2
- import { HashSet } from "./MutableSet.js";
3
- import { defaultOf, IDisposable, disposeSafe, IEnumerator, getEnumerator, IMap, IEqualityComparer, ISet } from "./Util.js";
4
- import { addToDict, getItemFromDict, tryGetValue, addToSet } from "./MapUtil.js";
5
- import { Dictionary } from "./MutableMap.js";
6
- import { int32 } from "./Int32.js";
7
- import { FSharpRef } from "./Types.js";
8
- import { FSharpList } from "./List.js";
9
-
10
- export function distinct<T>(xs: Iterable<T>, comparer: IEqualityComparer<T>): Iterable<T> {
11
- return delay<T>((): Iterable<T> => {
12
- const hashSet: ISet<T> = new HashSet<T>([], comparer);
13
- return filter<T>((x: T): boolean => addToSet(x, hashSet), xs);
14
- });
15
- }
16
-
17
- export function distinctBy<T, Key>(projection: ((arg0: T) => Key), xs: Iterable<T>, comparer: IEqualityComparer<Key>): Iterable<T> {
18
- return delay<T>((): Iterable<T> => {
19
- const hashSet: ISet<Key> = new HashSet<Key>([], comparer);
20
- return filter<T>((x: T): boolean => addToSet(projection(x), hashSet), xs);
21
- });
22
- }
23
-
24
- export function except<T>(itemsToExclude: Iterable<T>, xs: Iterable<T>, comparer: IEqualityComparer<T>): Iterable<T> {
25
- return delay<T>((): Iterable<T> => {
26
- const hashSet: ISet<T> = new HashSet<T>(itemsToExclude, comparer);
27
- return filter<T>((x: T): boolean => addToSet(x, hashSet), xs);
28
- });
29
- }
30
-
31
- export function countBy<T, Key>(projection: ((arg0: T) => Key), xs: Iterable<T>, comparer: IEqualityComparer<Key>): Iterable<[Key, int32]> {
32
- return delay<[Key, int32]>((): Iterable<[Key, int32]> => {
33
- const dict: IMap<Key, int32> = new Dictionary<Key, int32>([], comparer);
34
- const keys: Key[] = [];
35
- const enumerator: IEnumerator<T> = getEnumerator(xs);
36
- try {
37
- while (enumerator["System.Collections.IEnumerator.MoveNext"]()) {
38
- const key: Key = projection(enumerator["System.Collections.Generic.IEnumerator`1.get_Current"]());
39
- let matchValue: [boolean, int32];
40
- let outArg = 0;
41
- matchValue = ([tryGetValue(dict, key, new FSharpRef<int32>((): int32 => outArg, (v: int32): void => {
42
- outArg = (v | 0);
43
- })), outArg] as [boolean, int32]);
44
- if (matchValue[0]) {
45
- dict.set(key, matchValue[1] + 1);
46
- }
47
- else {
48
- dict.set(key, 1);
49
- void (keys.push(key));
50
- }
51
- }
52
- }
53
- finally {
54
- disposeSafe(enumerator as IDisposable);
55
- }
56
- return map<Key, [Key, int32]>((key_1: Key): [Key, int32] => ([key_1, getItemFromDict(dict, key_1)] as [Key, int32]), keys);
57
- });
58
- }
59
-
60
- export function groupBy<T, Key>(projection: ((arg0: T) => Key), xs: Iterable<T>, comparer: IEqualityComparer<Key>): Iterable<[Key, Iterable<T>]> {
61
- return delay<[Key, Iterable<T>]>((): Iterable<[Key, Iterable<T>]> => {
62
- const dict: IMap<Key, T[]> = new Dictionary<Key, T[]>([], comparer);
63
- const keys: Key[] = [];
64
- const enumerator: IEnumerator<T> = getEnumerator(xs);
65
- try {
66
- while (enumerator["System.Collections.IEnumerator.MoveNext"]()) {
67
- const x: T = enumerator["System.Collections.Generic.IEnumerator`1.get_Current"]();
68
- const key: Key = projection(x);
69
- let matchValue: [boolean, T[]];
70
- let outArg: T[] = defaultOf();
71
- matchValue = ([tryGetValue(dict, key, new FSharpRef<T[]>((): T[] => outArg, (v: T[]): void => {
72
- outArg = v;
73
- })), outArg] as [boolean, T[]]);
74
- if (matchValue[0]) {
75
- void (matchValue[1].push(x));
76
- }
77
- else {
78
- addToDict(dict, key, [x]);
79
- void (keys.push(key));
80
- }
81
- }
82
- }
83
- finally {
84
- disposeSafe(enumerator as IDisposable);
85
- }
86
- return map<Key, [Key, Iterable<T>]>((key_1: Key): [Key, Iterable<T>] => ([key_1, getItemFromDict(dict, key_1)] as [Key, Iterable<T>]), keys);
87
- });
88
- }
89
-
90
- export function Array_distinct<T>(xs: T[], comparer: IEqualityComparer<T>): T[] {
91
- return toArray<T>(distinct<T>(xs, comparer));
92
- }
93
-
94
- export function Array_distinctBy<T, Key>(projection: ((arg0: T) => Key), xs: T[], comparer: IEqualityComparer<Key>): T[] {
95
- return toArray<T>(distinctBy<T, Key>(projection, xs, comparer));
96
- }
97
-
98
- export function Array_except<T>(itemsToExclude: Iterable<T>, xs: T[], comparer: IEqualityComparer<T>): T[] {
99
- return toArray<T>(except<T>(itemsToExclude, xs, comparer));
100
- }
101
-
102
- export function Array_countBy<T, Key>(projection: ((arg0: T) => Key), xs: T[], comparer: IEqualityComparer<Key>): [Key, int32][] {
103
- return toArray<[Key, int32]>(countBy<T, Key>(projection, xs, comparer));
104
- }
105
-
106
- export function Array_groupBy<T, Key>(projection: ((arg0: T) => Key), xs: T[], comparer: IEqualityComparer<Key>): [Key, T[]][] {
107
- return toArray<[Key, T[]]>(map<[Key, Iterable<T>], [Key, T[]]>((tupledArg: [Key, Iterable<T>]): [Key, T[]] => ([tupledArg[0], toArray<T>(tupledArg[1])] as [Key, T[]]), groupBy<T, Key>(projection, xs, comparer)));
108
- }
109
-
110
- export function List_distinct<T>(xs: FSharpList<T>, comparer: IEqualityComparer<T>): FSharpList<T> {
111
- return toList<T>(distinct<T>(xs, comparer));
112
- }
113
-
114
- export function List_distinctBy<T, Key>(projection: ((arg0: T) => Key), xs: FSharpList<T>, comparer: IEqualityComparer<Key>): FSharpList<T> {
115
- return toList<T>(distinctBy<T, Key>(projection, xs, comparer));
116
- }
117
-
118
- export function List_except<T>(itemsToExclude: Iterable<T>, xs: FSharpList<T>, comparer: IEqualityComparer<T>): FSharpList<T> {
119
- return toList<T>(except<T>(itemsToExclude, xs, comparer));
120
- }
121
-
122
- export function List_countBy<T, Key>(projection: ((arg0: T) => Key), xs: FSharpList<T>, comparer: IEqualityComparer<Key>): FSharpList<[Key, int32]> {
123
- return toList<[Key, int32]>(countBy<T, Key>(projection, xs, comparer));
124
- }
125
-
126
- export function List_groupBy<T, Key>(projection: ((arg0: T) => Key), xs: FSharpList<T>, comparer: IEqualityComparer<Key>): FSharpList<[Key, FSharpList<T>]> {
127
- return toList<[Key, FSharpList<T>]>(map<[Key, Iterable<T>], [Key, FSharpList<T>]>((tupledArg: [Key, Iterable<T>]): [Key, FSharpList<T>] => ([tupledArg[0], toList<T>(tupledArg[1])] as [Key, FSharpList<T>]), groupBy<T, Key>(projection, xs, comparer)));
128
- }
129
-
1
+ import { toList, toArray, map, filter, delay } from "./Seq.js";
2
+ import { HashSet } from "./MutableSet.js";
3
+ import { defaultOf, IDisposable, disposeSafe, IEnumerator, getEnumerator, IMap, IEqualityComparer, ISet } from "./Util.js";
4
+ import { addToDict, getItemFromDict, tryGetValue, addToSet } from "./MapUtil.js";
5
+ import { Dictionary } from "./MutableMap.js";
6
+ import { int32 } from "./Int32.js";
7
+ import { FSharpRef } from "./Types.js";
8
+ import { FSharpList } from "./List.js";
9
+
10
+ export function distinct<T>(xs: Iterable<T>, comparer: IEqualityComparer<T>): Iterable<T> {
11
+ return delay<T>((): Iterable<T> => {
12
+ const hashSet: ISet<T> = new HashSet<T>([], comparer);
13
+ return filter<T>((x: T): boolean => addToSet(x, hashSet), xs);
14
+ });
15
+ }
16
+
17
+ export function distinctBy<T, Key>(projection: ((arg0: T) => Key), xs: Iterable<T>, comparer: IEqualityComparer<Key>): Iterable<T> {
18
+ return delay<T>((): Iterable<T> => {
19
+ const hashSet: ISet<Key> = new HashSet<Key>([], comparer);
20
+ return filter<T>((x: T): boolean => addToSet(projection(x), hashSet), xs);
21
+ });
22
+ }
23
+
24
+ export function except<T>(itemsToExclude: Iterable<T>, xs: Iterable<T>, comparer: IEqualityComparer<T>): Iterable<T> {
25
+ return delay<T>((): Iterable<T> => {
26
+ const hashSet: ISet<T> = new HashSet<T>(itemsToExclude, comparer);
27
+ return filter<T>((x: T): boolean => addToSet(x, hashSet), xs);
28
+ });
29
+ }
30
+
31
+ export function countBy<T, Key>(projection: ((arg0: T) => Key), xs: Iterable<T>, comparer: IEqualityComparer<Key>): Iterable<[Key, int32]> {
32
+ return delay<[Key, int32]>((): Iterable<[Key, int32]> => {
33
+ const dict: IMap<Key, int32> = new Dictionary<Key, int32>([], comparer);
34
+ const keys: Key[] = [];
35
+ const enumerator: IEnumerator<T> = getEnumerator(xs);
36
+ try {
37
+ while (enumerator["System.Collections.IEnumerator.MoveNext"]()) {
38
+ const key: Key = projection(enumerator["System.Collections.Generic.IEnumerator`1.get_Current"]());
39
+ let matchValue: [boolean, int32];
40
+ let outArg = 0;
41
+ matchValue = ([tryGetValue(dict, key, new FSharpRef<int32>((): int32 => (outArg | 0), (v: int32): void => {
42
+ outArg = (v | 0);
43
+ })), outArg] as [boolean, int32]);
44
+ if (matchValue[0]) {
45
+ dict.set(key, matchValue[1] + 1);
46
+ }
47
+ else {
48
+ dict.set(key, 1);
49
+ void (keys.push(key));
50
+ }
51
+ }
52
+ }
53
+ finally {
54
+ disposeSafe(enumerator as IDisposable);
55
+ }
56
+ return map<Key, [Key, int32]>((key_1: Key): [Key, int32] => ([key_1, getItemFromDict(dict, key_1)] as [Key, int32]), keys);
57
+ });
58
+ }
59
+
60
+ export function groupBy<T, Key>(projection: ((arg0: T) => Key), xs: Iterable<T>, comparer: IEqualityComparer<Key>): Iterable<[Key, Iterable<T>]> {
61
+ return delay<[Key, Iterable<T>]>((): Iterable<[Key, Iterable<T>]> => {
62
+ const dict: IMap<Key, T[]> = new Dictionary<Key, T[]>([], comparer);
63
+ const keys: Key[] = [];
64
+ const enumerator: IEnumerator<T> = getEnumerator(xs);
65
+ try {
66
+ while (enumerator["System.Collections.IEnumerator.MoveNext"]()) {
67
+ const x: T = enumerator["System.Collections.Generic.IEnumerator`1.get_Current"]();
68
+ const key: Key = projection(x);
69
+ let matchValue: [boolean, T[]];
70
+ let outArg: T[] = defaultOf();
71
+ matchValue = ([tryGetValue(dict, key, new FSharpRef<T[]>((): T[] => outArg, (v: T[]): void => {
72
+ outArg = v;
73
+ })), outArg] as [boolean, T[]]);
74
+ if (matchValue[0]) {
75
+ void (matchValue[1].push(x));
76
+ }
77
+ else {
78
+ addToDict(dict, key, [x]);
79
+ void (keys.push(key));
80
+ }
81
+ }
82
+ }
83
+ finally {
84
+ disposeSafe(enumerator as IDisposable);
85
+ }
86
+ return map<Key, [Key, Iterable<T>]>((key_1: Key): [Key, Iterable<T>] => ([key_1, getItemFromDict(dict, key_1)] as [Key, Iterable<T>]), keys);
87
+ });
88
+ }
89
+
90
+ export function Array_distinct<T>(xs: T[], comparer: IEqualityComparer<T>): T[] {
91
+ return toArray<T>(distinct<T>(xs, comparer));
92
+ }
93
+
94
+ export function Array_distinctBy<T, Key>(projection: ((arg0: T) => Key), xs: T[], comparer: IEqualityComparer<Key>): T[] {
95
+ return toArray<T>(distinctBy<T, Key>(projection, xs, comparer));
96
+ }
97
+
98
+ export function Array_except<T>(itemsToExclude: Iterable<T>, xs: T[], comparer: IEqualityComparer<T>): T[] {
99
+ return toArray<T>(except<T>(itemsToExclude, xs, comparer));
100
+ }
101
+
102
+ export function Array_countBy<T, Key>(projection: ((arg0: T) => Key), xs: T[], comparer: IEqualityComparer<Key>): [Key, int32][] {
103
+ return toArray<[Key, int32]>(countBy<T, Key>(projection, xs, comparer));
104
+ }
105
+
106
+ export function Array_groupBy<T, Key>(projection: ((arg0: T) => Key), xs: T[], comparer: IEqualityComparer<Key>): [Key, T[]][] {
107
+ return toArray<[Key, T[]]>(map<[Key, Iterable<T>], [Key, T[]]>((tupledArg: [Key, Iterable<T>]): [Key, T[]] => ([tupledArg[0], toArray<T>(tupledArg[1])] as [Key, T[]]), groupBy<T, Key>(projection, xs, comparer)));
108
+ }
109
+
110
+ export function List_distinct<T>(xs: FSharpList<T>, comparer: IEqualityComparer<T>): FSharpList<T> {
111
+ return toList<T>(distinct<T>(xs, comparer));
112
+ }
113
+
114
+ export function List_distinctBy<T, Key>(projection: ((arg0: T) => Key), xs: FSharpList<T>, comparer: IEqualityComparer<Key>): FSharpList<T> {
115
+ return toList<T>(distinctBy<T, Key>(projection, xs, comparer));
116
+ }
117
+
118
+ export function List_except<T>(itemsToExclude: Iterable<T>, xs: FSharpList<T>, comparer: IEqualityComparer<T>): FSharpList<T> {
119
+ return toList<T>(except<T>(itemsToExclude, xs, comparer));
120
+ }
121
+
122
+ export function List_countBy<T, Key>(projection: ((arg0: T) => Key), xs: FSharpList<T>, comparer: IEqualityComparer<Key>): FSharpList<[Key, int32]> {
123
+ return toList<[Key, int32]>(countBy<T, Key>(projection, xs, comparer));
124
+ }
125
+
126
+ export function List_groupBy<T, Key>(projection: ((arg0: T) => Key), xs: FSharpList<T>, comparer: IEqualityComparer<Key>): FSharpList<[Key, FSharpList<T>]> {
127
+ return toList<[Key, FSharpList<T>]>(map<[Key, Iterable<T>], [Key, FSharpList<T>]>((tupledArg: [Key, Iterable<T>]): [Key, FSharpList<T>] => ([tupledArg[0], toList<T>(tupledArg[1])] as [Key, FSharpList<T>]), groupBy<T, Key>(projection, xs, comparer)));
128
+ }
129
+