@nlozgachev/pipelined 0.53.0 → 0.55.0
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/dist/{InternalTypes-CDiDBAY4.d.mts → InternalTypes-DuK_XpTi.d.cts} +1 -1
- package/dist/{Validation-CvCuj9D2.d.mts → Validation-CbU7Z-kj.d.cts} +85 -94
- package/dist/{Validation-wDL4nEcO.d.ts → Validation-CmxZ3V4r.d.ts} +82 -91
- package/dist/{chunk-5OFVS5UZ.mjs → chunk-JSG7SFXS.js} +1 -1
- package/dist/{chunk-XFE3SQEE.mjs → chunk-MFJXL6J2.js} +53 -62
- package/dist/{chunk-L6GLADRU.mjs → chunk-NIE7VVZU.js} +4 -5
- package/dist/composition.cjs +533 -0
- package/dist/{composition.d.mts → composition.d.cts} +2 -2
- package/dist/composition.js +35 -503
- package/dist/core.cjs +2678 -0
- package/dist/{core.d.mts → core.d.cts} +12 -12
- package/dist/core.d.ts +9 -9
- package/dist/core.js +27 -2665
- package/dist/data.cjs +1612 -0
- package/dist/{data.d.mts → data.d.cts} +4 -4
- package/dist/data.d.ts +1 -1
- package/dist/data.js +14 -2137
- package/dist/index.cjs +4508 -0
- package/dist/{index.d.mts → index.d.cts} +7 -7
- package/dist/index.d.ts +1 -1
- package/dist/index.js +73 -4454
- package/dist/types.cjs +84 -0
- package/dist/{types.d.mts → types.d.cts} +2 -2
- package/dist/types.js +7 -81
- package/package.json +2 -1
- package/dist/composition.mjs +0 -65
- package/dist/core.mjs +0 -49
- package/dist/data.mjs +0 -22
- package/dist/index.mjs +0 -136
- package/dist/types.mjs +0 -10
- /package/dist/{Duration-B8joKzro.d.mts → Duration-B8joKzro.d.cts} +0 -0
- /package/dist/{chunk-DENXUTKL.mjs → chunk-OIIOGDHK.js} +0 -0
package/dist/data.cjs
ADDED
|
@@ -0,0 +1,1612 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/Data/index.ts
|
|
21
|
+
var Data_exports = {};
|
|
22
|
+
__export(Data_exports, {
|
|
23
|
+
Arr: () => Arr,
|
|
24
|
+
BigNum: () => BigNum,
|
|
25
|
+
Dict: () => Dict,
|
|
26
|
+
Json: () => Json,
|
|
27
|
+
Num: () => Num,
|
|
28
|
+
Rec: () => Rec,
|
|
29
|
+
Str: () => Str,
|
|
30
|
+
Uniq: () => Uniq
|
|
31
|
+
});
|
|
32
|
+
module.exports = __toCommonJS(Data_exports);
|
|
33
|
+
|
|
34
|
+
// src/Core/Deferred.ts
|
|
35
|
+
var Deferred;
|
|
36
|
+
((Deferred2) => {
|
|
37
|
+
let from;
|
|
38
|
+
((from2) => {
|
|
39
|
+
from2.Promise = (p) => (
|
|
40
|
+
// eslint-disable-next-line unicorn/no-thenable -- Deferred is intentionally thenable; it is the mechanism that makes Task awaitable
|
|
41
|
+
{ then: ((f) => p.then(f)) }
|
|
42
|
+
);
|
|
43
|
+
})(from = Deferred2.from || (Deferred2.from = {}));
|
|
44
|
+
let to;
|
|
45
|
+
((to2) => {
|
|
46
|
+
to2.Promise = (d) => new globalThis.Promise((resolve) => d.then(resolve));
|
|
47
|
+
})(to = Deferred2.to || (Deferred2.to = {}));
|
|
48
|
+
Deferred2.all = (deferreds) => from.Promise(globalThis.Promise.all(deferreds.map((d) => to.Promise(d))));
|
|
49
|
+
Deferred2.race = (deferreds) => from.Promise(globalThis.Promise.race(deferreds.map((d) => to.Promise(d))));
|
|
50
|
+
})(Deferred || (Deferred = {}));
|
|
51
|
+
|
|
52
|
+
// src/Core/Maybe.ts
|
|
53
|
+
var _none = { kind: "None" };
|
|
54
|
+
var Maybe;
|
|
55
|
+
((Maybe2) => {
|
|
56
|
+
let make;
|
|
57
|
+
((make2) => {
|
|
58
|
+
make2.some = (value) => ({ kind: "Some", value });
|
|
59
|
+
make2.none = () => _none;
|
|
60
|
+
})(make = Maybe2.make || (Maybe2.make = {}));
|
|
61
|
+
let is;
|
|
62
|
+
((is2) => {
|
|
63
|
+
is2.some = (data) => data.kind === "Some";
|
|
64
|
+
is2.none = (data) => data.kind === "None";
|
|
65
|
+
})(is = Maybe2.is || (Maybe2.is = {}));
|
|
66
|
+
let to;
|
|
67
|
+
((to2) => {
|
|
68
|
+
to2.nullable = (data) => is.some(data) ? data.value : null;
|
|
69
|
+
to2.undefined = (data) => is.some(data) ? data.value : globalThis.undefined;
|
|
70
|
+
to2.Result = (onNone) => (data) => is.some(data) ? Result.make.ok(data.value) : Result.make.err(onNone());
|
|
71
|
+
})(to = Maybe2.to || (Maybe2.to = {}));
|
|
72
|
+
let from;
|
|
73
|
+
((from2) => {
|
|
74
|
+
from2.nullable = (value) => value === null || value === void 0 ? make.none() : make.some(value);
|
|
75
|
+
from2.Predicate = (pred) => (a) => pred(a) ? make.some(a) : make.none();
|
|
76
|
+
from2.Result = (data) => Result.is.ok(data) ? make.some(data.value) : make.none();
|
|
77
|
+
})(from = Maybe2.from || (Maybe2.from = {}));
|
|
78
|
+
Maybe2.map = (f) => (data) => is.some(data) ? make.some(f(data.value)) : data;
|
|
79
|
+
Maybe2.chain = (f) => (data) => is.some(data) ? f(data.value) : data;
|
|
80
|
+
Maybe2.fold = (onNone, onSome) => (data) => is.some(data) ? onSome(data.value) : onNone();
|
|
81
|
+
Maybe2.match = (cases) => (data) => is.some(data) ? cases.some(data.value) : cases.none();
|
|
82
|
+
Maybe2.getOrElse = (defaultValue) => (data) => is.some(data) ? data.value : defaultValue();
|
|
83
|
+
Maybe2.tap = (f) => (data) => {
|
|
84
|
+
if (is.some(data)) {
|
|
85
|
+
f(data.value);
|
|
86
|
+
}
|
|
87
|
+
return data;
|
|
88
|
+
};
|
|
89
|
+
Maybe2.filter = (predicate) => (data) => is.some(data) ? predicate(data.value) ? data : make.none() : data;
|
|
90
|
+
Maybe2.recover = (fallback) => (data) => is.some(data) ? data : fallback();
|
|
91
|
+
Maybe2.ap = (arg) => (data) => is.some(data) && is.some(arg) ? make.some(data.value(arg.value)) : make.none();
|
|
92
|
+
Maybe2.bindTo = (key) => (data) => (0, Maybe2.map)((a) => ({ [key]: a }))(data);
|
|
93
|
+
Maybe2.bind = (key, f) => (data) => (0, Maybe2.chain)(
|
|
94
|
+
(a) => (0, Maybe2.map)((b) => ({ ...a, [key]: b }))(f(a))
|
|
95
|
+
)(data);
|
|
96
|
+
Maybe2.struct = (fields) => {
|
|
97
|
+
const result = {};
|
|
98
|
+
for (const key in fields) {
|
|
99
|
+
if (Object.hasOwn(fields, key)) {
|
|
100
|
+
const res = fields[key];
|
|
101
|
+
if (is.none(res)) {
|
|
102
|
+
return res;
|
|
103
|
+
}
|
|
104
|
+
result[key] = res.value;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return make.some(result);
|
|
108
|
+
};
|
|
109
|
+
Maybe2.transposeResult = (data) => is.none(data) ? Result.make.ok(make.none()) : Result.is.ok(data.value) ? Result.make.ok(make.some(data.value.value)) : Result.make.err(data.value.error);
|
|
110
|
+
})(Maybe || (Maybe = {}));
|
|
111
|
+
|
|
112
|
+
// src/Core/Result.ts
|
|
113
|
+
var Result;
|
|
114
|
+
((Result2) => {
|
|
115
|
+
let make;
|
|
116
|
+
((make2) => {
|
|
117
|
+
make2.ok = (value) => ({ kind: "Ok", value });
|
|
118
|
+
make2.err = (e) => ({ kind: "Err", error: e });
|
|
119
|
+
})(make = Result2.make || (Result2.make = {}));
|
|
120
|
+
let is;
|
|
121
|
+
((is2) => {
|
|
122
|
+
is2.ok = (data) => data.kind === "Ok";
|
|
123
|
+
is2.err = (data) => data.kind === "Err";
|
|
124
|
+
})(is = Result2.is || (Result2.is = {}));
|
|
125
|
+
Result2.tryCatch = (f, options) => {
|
|
126
|
+
try {
|
|
127
|
+
return make.ok(f());
|
|
128
|
+
} catch (error) {
|
|
129
|
+
return make.err(options.onError(error));
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
Result2.map = (f) => (data) => is.ok(data) ? make.ok(f(data.value)) : data;
|
|
133
|
+
Result2.mapError = (f) => (data) => is.err(data) ? make.err(f(data.error)) : data;
|
|
134
|
+
Result2.chain = (f) => (data) => is.ok(data) ? f(data.value) : data;
|
|
135
|
+
Result2.fold = (onErr, onOk) => (data) => is.ok(data) ? onOk(data.value) : onErr(data.error);
|
|
136
|
+
Result2.match = (cases) => (data) => is.ok(data) ? cases.ok(data.value) : cases.err(data.error);
|
|
137
|
+
Result2.getOrElse = (defaultValue) => (data) => is.ok(data) ? data.value : defaultValue();
|
|
138
|
+
Result2.tap = (f) => (data) => {
|
|
139
|
+
if (is.ok(data)) {
|
|
140
|
+
f(data.value);
|
|
141
|
+
}
|
|
142
|
+
return data;
|
|
143
|
+
};
|
|
144
|
+
Result2.tapError = (f) => (data) => {
|
|
145
|
+
if (is.err(data)) {
|
|
146
|
+
f(data.error);
|
|
147
|
+
}
|
|
148
|
+
return data;
|
|
149
|
+
};
|
|
150
|
+
let from;
|
|
151
|
+
((from2) => {
|
|
152
|
+
from2.Predicate = (pred, onFalse) => (a) => pred(a) ? make.ok(a) : make.err(onFalse(a));
|
|
153
|
+
from2.nullable = (onNull) => (value) => value === null || value === void 0 ? make.err(onNull()) : make.ok(value);
|
|
154
|
+
from2.Maybe = (onNone) => (maybe) => Maybe.is.none(maybe) ? make.err(onNone()) : make.ok(maybe.value);
|
|
155
|
+
from2.Validation = (combineErrors) => (val) => Validation.is.passed(val) ? make.ok(val.value) : make.err(combineErrors(val.errors));
|
|
156
|
+
})(from = Result2.from || (Result2.from = {}));
|
|
157
|
+
Result2.recover = (fallback) => (data) => is.ok(data) ? data : fallback(data.error);
|
|
158
|
+
Result2.recoverUnless = (isBlocked, fallback) => (data) => is.err(data) && !isBlocked(data.error) ? fallback() : data;
|
|
159
|
+
let to;
|
|
160
|
+
((to2) => {
|
|
161
|
+
to2.Maybe = (data) => is.ok(data) ? Maybe.make.some(data.value) : Maybe.make.none();
|
|
162
|
+
to2.Validation = (data) => Validation.from.Result(data);
|
|
163
|
+
})(to = Result2.to || (Result2.to = {}));
|
|
164
|
+
Result2.transposeMaybe = (data) => is.err(data) ? Maybe.make.some(data) : Maybe.is.some(data.value) ? Maybe.make.some(make.ok(data.value.value)) : Maybe.make.none();
|
|
165
|
+
Result2.ap = (arg) => (data) => is.ok(data) && is.ok(arg) ? make.ok(data.value(arg.value)) : is.err(data) ? data : arg;
|
|
166
|
+
Result2.bindTo = (key) => (data) => (0, Result2.map)((a) => ({ [key]: a }))(data);
|
|
167
|
+
Result2.bind = (key, f) => (data) => (0, Result2.chain)(
|
|
168
|
+
(a) => (0, Result2.map)((b) => ({ ...a, [key]: b }))(f(a))
|
|
169
|
+
)(data);
|
|
170
|
+
Result2.struct = (fields) => {
|
|
171
|
+
const result = {};
|
|
172
|
+
for (const key in fields) {
|
|
173
|
+
if (Object.hasOwn(fields, key)) {
|
|
174
|
+
const res = fields[key];
|
|
175
|
+
if (is.err(res)) {
|
|
176
|
+
return res;
|
|
177
|
+
}
|
|
178
|
+
result[key] = res.value;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
return make.ok(result);
|
|
182
|
+
};
|
|
183
|
+
Result2.ensure = (predicate, onFail) => (data) => is.err(data) ? data : predicate(data.value) ? data : make.err(onFail(data.value));
|
|
184
|
+
Result2.bimap = (onErr, onOk) => (data) => is.ok(data) ? make.ok(onOk(data.value)) : make.err(onErr(data.error));
|
|
185
|
+
})(Result || (Result = {}));
|
|
186
|
+
|
|
187
|
+
// src/internal/InternalTypes.ts
|
|
188
|
+
var isNonEmptyArr = (list) => list.length > 0;
|
|
189
|
+
|
|
190
|
+
// src/Core/Validation.ts
|
|
191
|
+
var Validation;
|
|
192
|
+
((Validation2) => {
|
|
193
|
+
let make;
|
|
194
|
+
((make2) => {
|
|
195
|
+
make2.passed = (value) => ({ kind: "Passed", value });
|
|
196
|
+
make2.failed = (error) => ({ kind: "Failed", errors: [error] });
|
|
197
|
+
make2.failedAll = (errors) => ({ kind: "Failed", errors });
|
|
198
|
+
})(make = Validation2.make || (Validation2.make = {}));
|
|
199
|
+
let is;
|
|
200
|
+
((is2) => {
|
|
201
|
+
is2.passed = (data) => data.kind === "Passed";
|
|
202
|
+
is2.failed = (data) => data.kind === "Failed";
|
|
203
|
+
})(is = Validation2.is || (Validation2.is = {}));
|
|
204
|
+
Validation2.tryCatch = (f, options) => {
|
|
205
|
+
try {
|
|
206
|
+
return make.passed(f());
|
|
207
|
+
} catch (error) {
|
|
208
|
+
return make.failed(options.onError(error));
|
|
209
|
+
}
|
|
210
|
+
};
|
|
211
|
+
let from;
|
|
212
|
+
((from2) => {
|
|
213
|
+
from2.Predicate = (pred, onFalse) => (a) => pred(a) ? make.passed(a) : make.failed(onFalse(a));
|
|
214
|
+
from2.nullable = (onNull) => (value) => value === null || value === void 0 ? make.failed(onNull()) : make.passed(value);
|
|
215
|
+
from2.Maybe = (onNone) => (maybe) => Maybe.is.none(maybe) ? make.failed(onNone()) : make.passed(maybe.value);
|
|
216
|
+
from2.Result = (data) => data.kind === "Ok" ? make.passed(data.value) : make.failed(data.error);
|
|
217
|
+
})(from = Validation2.from || (Validation2.from = {}));
|
|
218
|
+
Validation2.map = (f) => (data) => is.passed(data) ? make.passed(f(data.value)) : data;
|
|
219
|
+
Validation2.mapError = (f) => (data) => is.failed(data) ? make.failedAll(data.errors.map(f)) : data;
|
|
220
|
+
Validation2.ap = (arg) => (data) => {
|
|
221
|
+
if (is.passed(data)) {
|
|
222
|
+
return is.passed(arg) ? make.passed(data.value(arg.value)) : make.failedAll(arg.errors);
|
|
223
|
+
}
|
|
224
|
+
return is.passed(arg) ? make.failedAll(data.errors) : make.failedAll([...data.errors, ...arg.errors]);
|
|
225
|
+
};
|
|
226
|
+
Validation2.apCustom = (concat) => (arg) => (data) => {
|
|
227
|
+
if (is.passed(data)) {
|
|
228
|
+
return is.passed(arg) ? make.passed(data.value(arg.value)) : make.failedAll(arg.errors);
|
|
229
|
+
}
|
|
230
|
+
return is.passed(arg) ? make.failedAll(data.errors) : make.failedAll(concat(data.errors, arg.errors));
|
|
231
|
+
};
|
|
232
|
+
Validation2.fold = (onFailed, onPassed) => (data) => is.passed(data) ? onPassed(data.value) : onFailed(data.errors);
|
|
233
|
+
Validation2.match = (cases) => (data) => is.passed(data) ? cases.passed(data.value) : cases.failed(data.errors);
|
|
234
|
+
Validation2.getOrElse = (defaultValue) => (data) => is.passed(data) ? data.value : defaultValue();
|
|
235
|
+
Validation2.tap = (f) => (data) => {
|
|
236
|
+
if (is.passed(data)) {
|
|
237
|
+
f(data.value);
|
|
238
|
+
}
|
|
239
|
+
return data;
|
|
240
|
+
};
|
|
241
|
+
Validation2.tapError = (f) => (data) => {
|
|
242
|
+
if (is.failed(data)) {
|
|
243
|
+
f(data.errors);
|
|
244
|
+
}
|
|
245
|
+
return data;
|
|
246
|
+
};
|
|
247
|
+
Validation2.recover = (fallback) => (data) => is.passed(data) ? data : fallback(data.errors);
|
|
248
|
+
Validation2.recoverUnless = (isBlocked, fallback) => (data) => is.failed(data) && !data.errors.some(isBlocked) ? fallback() : data;
|
|
249
|
+
let to;
|
|
250
|
+
((to2) => {
|
|
251
|
+
function Result2(arg) {
|
|
252
|
+
if (typeof arg === "function") {
|
|
253
|
+
const combine = arg;
|
|
254
|
+
return (val) => is.passed(val) ? Result.make.ok(val.value) : Result.make.err(combine(val.errors));
|
|
255
|
+
}
|
|
256
|
+
return is.passed(arg) ? Result.make.ok(arg.value) : Result.make.err(arg.errors);
|
|
257
|
+
}
|
|
258
|
+
to2.Result = Result2;
|
|
259
|
+
to2.Maybe = (data) => is.passed(data) ? Maybe.make.some(data.value) : Maybe.make.none();
|
|
260
|
+
})(to = Validation2.to || (Validation2.to = {}));
|
|
261
|
+
Validation2.product = (first, second) => {
|
|
262
|
+
if (is.passed(first)) {
|
|
263
|
+
return is.passed(second) ? make.passed([first.value, second.value]) : make.failedAll(second.errors);
|
|
264
|
+
}
|
|
265
|
+
return is.passed(second) ? make.failedAll(first.errors) : make.failedAll([...first.errors, ...second.errors]);
|
|
266
|
+
};
|
|
267
|
+
Validation2.productAll = (data) => {
|
|
268
|
+
const values = [];
|
|
269
|
+
const errors = [];
|
|
270
|
+
for (const v of data) {
|
|
271
|
+
if (is.passed(v)) {
|
|
272
|
+
values.push(v.value);
|
|
273
|
+
} else {
|
|
274
|
+
errors.push(...v.errors);
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
return isNonEmptyArr(errors) ? make.failedAll(errors) : make.passed(values);
|
|
278
|
+
};
|
|
279
|
+
Validation2.struct = (fields) => {
|
|
280
|
+
const record = {};
|
|
281
|
+
const errors = [];
|
|
282
|
+
for (const key in fields) {
|
|
283
|
+
if (Object.hasOwn(fields, key)) {
|
|
284
|
+
const val = fields[key];
|
|
285
|
+
if (is.passed(val)) {
|
|
286
|
+
record[key] = val.value;
|
|
287
|
+
} else {
|
|
288
|
+
errors.push(...val.errors);
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
return isNonEmptyArr(errors) ? make.failedAll(errors) : make.passed(record);
|
|
293
|
+
};
|
|
294
|
+
})(Validation || (Validation = {}));
|
|
295
|
+
|
|
296
|
+
// src/Data/Arr.ts
|
|
297
|
+
var ArrMaybe;
|
|
298
|
+
((ArrMaybe2) => {
|
|
299
|
+
ArrMaybe2.traverse = (f) => (data) => {
|
|
300
|
+
const n = data.length;
|
|
301
|
+
const result = new Array(n);
|
|
302
|
+
for (let i = 0; i < n; i++) {
|
|
303
|
+
const mapped = f(data[i]);
|
|
304
|
+
if (mapped.kind === "None") {
|
|
305
|
+
return Maybe.make.none();
|
|
306
|
+
}
|
|
307
|
+
result[i] = mapped.value;
|
|
308
|
+
}
|
|
309
|
+
return Maybe.make.some(result);
|
|
310
|
+
};
|
|
311
|
+
ArrMaybe2.sequence = (data) => (0, ArrMaybe2.traverse)((a) => a)(data);
|
|
312
|
+
})(ArrMaybe || (ArrMaybe = {}));
|
|
313
|
+
var ArrResult;
|
|
314
|
+
((ArrResult2) => {
|
|
315
|
+
ArrResult2.traverse = (f) => (data) => {
|
|
316
|
+
const n = data.length;
|
|
317
|
+
const result = new Array(n);
|
|
318
|
+
for (let i = 0; i < n; i++) {
|
|
319
|
+
const mapped = f(data[i]);
|
|
320
|
+
if (mapped.kind === "Err") {
|
|
321
|
+
return mapped;
|
|
322
|
+
}
|
|
323
|
+
result[i] = mapped.value;
|
|
324
|
+
}
|
|
325
|
+
return Result.make.ok(result);
|
|
326
|
+
};
|
|
327
|
+
ArrResult2.sequence = (data) => (0, ArrResult2.traverse)((a) => a)(data);
|
|
328
|
+
})(ArrResult || (ArrResult = {}));
|
|
329
|
+
var ArrTaskResult;
|
|
330
|
+
((ArrTaskResult2) => {
|
|
331
|
+
ArrTaskResult2.traverse = (f) => (data) => () => Deferred.from.Promise((async () => {
|
|
332
|
+
const result = [];
|
|
333
|
+
for (const a of data) {
|
|
334
|
+
const r = await Deferred.to.Promise(f(a)());
|
|
335
|
+
if (Result.is.err(r)) {
|
|
336
|
+
return r;
|
|
337
|
+
}
|
|
338
|
+
result.push(r.value);
|
|
339
|
+
}
|
|
340
|
+
return Result.make.ok(result);
|
|
341
|
+
})());
|
|
342
|
+
ArrTaskResult2.sequence = (data) => (0, ArrTaskResult2.traverse)((a) => a)(data);
|
|
343
|
+
})(ArrTaskResult || (ArrTaskResult = {}));
|
|
344
|
+
var ArrTask;
|
|
345
|
+
((ArrTask2) => {
|
|
346
|
+
ArrTask2.traverse = (f) => (data) => () => Deferred.from.Promise(Promise.all(data.map((a) => Deferred.to.Promise(f(a)()))));
|
|
347
|
+
ArrTask2.sequence = (data) => (0, ArrTask2.traverse)((a) => a)(data);
|
|
348
|
+
ArrTask2.Result = ArrTaskResult;
|
|
349
|
+
})(ArrTask || (ArrTask = {}));
|
|
350
|
+
var ArrNonEmpty;
|
|
351
|
+
((ArrNonEmpty2) => {
|
|
352
|
+
ArrNonEmpty2.singleton = (value) => [value];
|
|
353
|
+
let from;
|
|
354
|
+
((from2) => {
|
|
355
|
+
from2.Array = (data) => isNonEmptyArr(data) ? Maybe.make.some(data) : Maybe.make.none();
|
|
356
|
+
})(from = ArrNonEmpty2.from || (ArrNonEmpty2.from = {}));
|
|
357
|
+
ArrNonEmpty2.head = (data) => data[0];
|
|
358
|
+
ArrNonEmpty2.last = (data) => data[data.length - 1];
|
|
359
|
+
ArrNonEmpty2.tail = (data) => data.slice(1);
|
|
360
|
+
ArrNonEmpty2.reduce = (f) => (data) => data.reduce(f);
|
|
361
|
+
ArrNonEmpty2.map = (f) => (data) => Arr.map(f)(data);
|
|
362
|
+
ArrNonEmpty2.mapWithIndex = (f) => (data) => Arr.mapWithIndex(f)(data);
|
|
363
|
+
ArrNonEmpty2.intersperse = (sep) => (data) => Arr.intersperse(sep)(data);
|
|
364
|
+
ArrNonEmpty2.concat = (other) => (data) => Arr.concat(other)(data);
|
|
365
|
+
ArrNonEmpty2.reverse = (data) => Arr.reverse(data);
|
|
366
|
+
})(ArrNonEmpty || (ArrNonEmpty = {}));
|
|
367
|
+
var Arr;
|
|
368
|
+
((Arr2) => {
|
|
369
|
+
Arr2.head = (data) => data.length > 0 ? Maybe.make.some(data[0]) : Maybe.make.none();
|
|
370
|
+
Arr2.last = (data) => data.length > 0 ? Maybe.make.some(data[data.length - 1]) : Maybe.make.none();
|
|
371
|
+
Arr2.tail = (data) => data.length > 0 ? Maybe.make.some(data.slice(1)) : Maybe.make.none();
|
|
372
|
+
Arr2.init = (data) => data.length > 0 ? Maybe.make.some(data.slice(0, -1)) : Maybe.make.none();
|
|
373
|
+
Arr2.findFirst = (predicate) => (data) => {
|
|
374
|
+
const idx = data.findIndex(predicate);
|
|
375
|
+
return idx !== -1 ? Maybe.make.some(data[idx]) : Maybe.make.none();
|
|
376
|
+
};
|
|
377
|
+
Arr2.findLast = (predicate) => (data) => {
|
|
378
|
+
for (let i = data.length - 1; i >= 0; i--) {
|
|
379
|
+
if (predicate(data[i])) {
|
|
380
|
+
return Maybe.make.some(data[i]);
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
return Maybe.make.none();
|
|
384
|
+
};
|
|
385
|
+
Arr2.findIndex = (predicate) => (data) => {
|
|
386
|
+
const idx = data.findIndex(predicate);
|
|
387
|
+
return idx !== -1 ? Maybe.make.some(idx) : Maybe.make.none();
|
|
388
|
+
};
|
|
389
|
+
Arr2.map = (f) => (data) => {
|
|
390
|
+
const n = data.length;
|
|
391
|
+
const result = new Array(n);
|
|
392
|
+
for (let i = 0; i < n; i++) {
|
|
393
|
+
result[i] = f(data[i]);
|
|
394
|
+
}
|
|
395
|
+
return result;
|
|
396
|
+
};
|
|
397
|
+
Arr2.mapWithIndex = (f) => (data) => {
|
|
398
|
+
const n = data.length;
|
|
399
|
+
const result = new Array(n);
|
|
400
|
+
for (let i = 0; i < n; i++) {
|
|
401
|
+
result[i] = f(i, data[i]);
|
|
402
|
+
}
|
|
403
|
+
return result;
|
|
404
|
+
};
|
|
405
|
+
Arr2.filter = (predicate) => (data) => {
|
|
406
|
+
const n = data.length;
|
|
407
|
+
const result = [];
|
|
408
|
+
for (let i = 0; i < n; i++) {
|
|
409
|
+
if (predicate(data[i])) {
|
|
410
|
+
result.push(data[i]);
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
return result;
|
|
414
|
+
};
|
|
415
|
+
Arr2.filterMap = (f) => (data) => {
|
|
416
|
+
const result = [];
|
|
417
|
+
for (let i = 0; i < data.length; i++) {
|
|
418
|
+
const mapped = f(data[i]);
|
|
419
|
+
if (mapped.kind === "Some") {
|
|
420
|
+
result.push(mapped.value);
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
return result;
|
|
424
|
+
};
|
|
425
|
+
Arr2.partition = (predicate) => (data) => {
|
|
426
|
+
const pass = [];
|
|
427
|
+
const fail = [];
|
|
428
|
+
for (const a of data) {
|
|
429
|
+
(predicate(a) ? pass : fail).push(a);
|
|
430
|
+
}
|
|
431
|
+
return [pass, fail];
|
|
432
|
+
};
|
|
433
|
+
Arr2.compact = (data) => {
|
|
434
|
+
const result = [];
|
|
435
|
+
for (const item of data) {
|
|
436
|
+
if (item.kind === "Some") {
|
|
437
|
+
result.push(item.value);
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
return result;
|
|
441
|
+
};
|
|
442
|
+
Arr2.separate = (data) => {
|
|
443
|
+
const errors = [];
|
|
444
|
+
const successes = [];
|
|
445
|
+
for (const item of data) {
|
|
446
|
+
if (item.kind === "Ok") {
|
|
447
|
+
successes.push(item.value);
|
|
448
|
+
} else {
|
|
449
|
+
errors.push(item.error);
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
return [errors, successes];
|
|
453
|
+
};
|
|
454
|
+
Arr2.partitionMap = (f) => (data) => {
|
|
455
|
+
const errors = [];
|
|
456
|
+
const successes = [];
|
|
457
|
+
for (const item of data) {
|
|
458
|
+
const mapped = f(item);
|
|
459
|
+
if (mapped.kind === "Ok") {
|
|
460
|
+
successes.push(mapped.value);
|
|
461
|
+
} else {
|
|
462
|
+
errors.push(mapped.error);
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
return [errors, successes];
|
|
466
|
+
};
|
|
467
|
+
Arr2.groupBy = (f) => (data) => {
|
|
468
|
+
const result = {};
|
|
469
|
+
for (const a of data) {
|
|
470
|
+
const key = f(a);
|
|
471
|
+
if (!result[key]) {
|
|
472
|
+
result[key] = [];
|
|
473
|
+
}
|
|
474
|
+
result[key].push(a);
|
|
475
|
+
}
|
|
476
|
+
return result;
|
|
477
|
+
};
|
|
478
|
+
Arr2.uniq = (data) => [...new Set(data)];
|
|
479
|
+
Arr2.uniqBy = (f) => (data) => {
|
|
480
|
+
const seen = /* @__PURE__ */ new Set();
|
|
481
|
+
const result = [];
|
|
482
|
+
for (const a of data) {
|
|
483
|
+
const key = f(a);
|
|
484
|
+
if (!seen.has(key)) {
|
|
485
|
+
seen.add(key);
|
|
486
|
+
result.push(a);
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
return result;
|
|
490
|
+
};
|
|
491
|
+
Arr2.uniqWith = (eq) => (data) => {
|
|
492
|
+
const result = [];
|
|
493
|
+
for (const a of data) {
|
|
494
|
+
if (!result.some((x) => eq(x, a))) {
|
|
495
|
+
result.push(a);
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
return result;
|
|
499
|
+
};
|
|
500
|
+
Arr2.sortBy = (compare) => (data) => {
|
|
501
|
+
const arr = data;
|
|
502
|
+
if (typeof arr.toSorted === "function") {
|
|
503
|
+
return arr.toSorted(compare);
|
|
504
|
+
}
|
|
505
|
+
return [...data].toSorted(compare);
|
|
506
|
+
};
|
|
507
|
+
Arr2.sortWith = (ord) => (data) => {
|
|
508
|
+
const arr = data;
|
|
509
|
+
if (typeof arr.toSorted === "function") {
|
|
510
|
+
return arr.toSorted(ord);
|
|
511
|
+
}
|
|
512
|
+
return [...data].sort(ord);
|
|
513
|
+
};
|
|
514
|
+
Arr2.zip = (other) => (data) => {
|
|
515
|
+
const len = Math.min(data.length, other.length);
|
|
516
|
+
const result = new Array(len);
|
|
517
|
+
for (let i = 0; i < len; i++) {
|
|
518
|
+
result[i] = [data[i], other[i]];
|
|
519
|
+
}
|
|
520
|
+
return result;
|
|
521
|
+
};
|
|
522
|
+
Arr2.zipWith = (f) => (other) => (data) => {
|
|
523
|
+
const len = Math.min(data.length, other.length);
|
|
524
|
+
const result = new Array(len);
|
|
525
|
+
for (let i = 0; i < len; i++) {
|
|
526
|
+
result[i] = f(data[i], other[i]);
|
|
527
|
+
}
|
|
528
|
+
return result;
|
|
529
|
+
};
|
|
530
|
+
Arr2.intersperse = (sep) => (data) => {
|
|
531
|
+
if (data.length <= 1) {
|
|
532
|
+
return data;
|
|
533
|
+
}
|
|
534
|
+
const result = [data[0]];
|
|
535
|
+
for (let i = 1; i < data.length; i++) {
|
|
536
|
+
result.push(sep, data[i]);
|
|
537
|
+
}
|
|
538
|
+
return result;
|
|
539
|
+
};
|
|
540
|
+
Arr2.concat = (other) => (data) => [...data, ...other];
|
|
541
|
+
Arr2.chunksOf = (n) => (data) => {
|
|
542
|
+
if (n <= 0) {
|
|
543
|
+
return [];
|
|
544
|
+
}
|
|
545
|
+
const result = [];
|
|
546
|
+
for (let i = 0; i < data.length; i += n) {
|
|
547
|
+
result.push(data.slice(i, i + n));
|
|
548
|
+
}
|
|
549
|
+
return result;
|
|
550
|
+
};
|
|
551
|
+
Arr2.flatten = (data) => {
|
|
552
|
+
let totalLen = 0;
|
|
553
|
+
const outerLen = data.length;
|
|
554
|
+
for (let i = 0; i < outerLen; i++) {
|
|
555
|
+
totalLen += data[i].length;
|
|
556
|
+
}
|
|
557
|
+
const result = new Array(totalLen);
|
|
558
|
+
let idx = 0;
|
|
559
|
+
for (let i = 0; i < outerLen; i++) {
|
|
560
|
+
const chunk = data[i];
|
|
561
|
+
const innerLen = chunk.length;
|
|
562
|
+
for (let j = 0; j < innerLen; j++) {
|
|
563
|
+
result[idx++] = chunk[j];
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
return result;
|
|
567
|
+
};
|
|
568
|
+
Arr2.flatMap = (f) => (data) => {
|
|
569
|
+
const n = data.length;
|
|
570
|
+
const result = [];
|
|
571
|
+
for (let i = 0; i < n; i++) {
|
|
572
|
+
const chunk = f(data[i]);
|
|
573
|
+
const m = chunk.length;
|
|
574
|
+
for (let j = 0; j < m; j++) {
|
|
575
|
+
result.push(chunk[j]);
|
|
576
|
+
}
|
|
577
|
+
}
|
|
578
|
+
return result;
|
|
579
|
+
};
|
|
580
|
+
Arr2.reduce = (initial, f) => (data) => data.reduce(f, initial);
|
|
581
|
+
const _traverseTask = Object.assign((f) => ArrTask.traverse(f), {
|
|
582
|
+
Result: ArrTaskResult.traverse
|
|
583
|
+
});
|
|
584
|
+
const _sequenceTask = Object.assign((data) => ArrTask.sequence(data), {
|
|
585
|
+
Result: ArrTaskResult.sequence
|
|
586
|
+
});
|
|
587
|
+
let traverse;
|
|
588
|
+
((traverse2) => {
|
|
589
|
+
traverse2.Maybe = ArrMaybe.traverse;
|
|
590
|
+
traverse2.Result = ArrResult.traverse;
|
|
591
|
+
traverse2.Task = _traverseTask;
|
|
592
|
+
})(traverse = Arr2.traverse || (Arr2.traverse = {}));
|
|
593
|
+
let sequence;
|
|
594
|
+
((sequence2) => {
|
|
595
|
+
sequence2.Maybe = ArrMaybe.sequence;
|
|
596
|
+
sequence2.Result = ArrResult.sequence;
|
|
597
|
+
sequence2.Task = _sequenceTask;
|
|
598
|
+
})(sequence = Arr2.sequence || (Arr2.sequence = {}));
|
|
599
|
+
let is;
|
|
600
|
+
((is2) => {
|
|
601
|
+
is2.empty = (data) => data.length === 0;
|
|
602
|
+
is2.nonEmpty = (data) => isNonEmptyArr(data);
|
|
603
|
+
})(is = Arr2.is || (Arr2.is = {}));
|
|
604
|
+
Arr2.prepend = (value) => (data) => [value, ...data];
|
|
605
|
+
Arr2.append = (value) => (data) => [...data, value];
|
|
606
|
+
Arr2.size = (data) => data.length;
|
|
607
|
+
Arr2.some = (predicate) => (data) => {
|
|
608
|
+
const n = data.length;
|
|
609
|
+
for (let i = 0; i < n; i++) {
|
|
610
|
+
if (predicate(data[i])) {
|
|
611
|
+
return true;
|
|
612
|
+
}
|
|
613
|
+
}
|
|
614
|
+
return false;
|
|
615
|
+
};
|
|
616
|
+
Arr2.every = (predicate) => (data) => {
|
|
617
|
+
const n = data.length;
|
|
618
|
+
for (let i = 0; i < n; i++) {
|
|
619
|
+
if (!predicate(data[i])) {
|
|
620
|
+
return false;
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
return true;
|
|
624
|
+
};
|
|
625
|
+
Arr2.reverse = (data) => [...data].toReversed();
|
|
626
|
+
Arr2.insertAt = (index, item) => (data) => {
|
|
627
|
+
const i = Math.max(0, Math.min(index, data.length));
|
|
628
|
+
const arr = data;
|
|
629
|
+
if (typeof arr.toSpliced === "function") {
|
|
630
|
+
return arr.toSpliced(i, 0, item);
|
|
631
|
+
}
|
|
632
|
+
const result = [...data];
|
|
633
|
+
result.splice(i, 0, item);
|
|
634
|
+
return result;
|
|
635
|
+
};
|
|
636
|
+
Arr2.removeAt = (index) => (data) => {
|
|
637
|
+
if (index < 0 || index >= data.length) {
|
|
638
|
+
return data;
|
|
639
|
+
}
|
|
640
|
+
const arr = data;
|
|
641
|
+
if (typeof arr.toSpliced === "function") {
|
|
642
|
+
return arr.toSpliced(index, 1);
|
|
643
|
+
}
|
|
644
|
+
const result = [...data];
|
|
645
|
+
result.splice(index, 1);
|
|
646
|
+
return result;
|
|
647
|
+
};
|
|
648
|
+
Arr2.take = (n) => (data) => n <= 0 ? [] : data.slice(0, n);
|
|
649
|
+
Arr2.drop = (n) => (data) => data.slice(n);
|
|
650
|
+
Arr2.takeWhile = (predicate) => (data) => {
|
|
651
|
+
const result = [];
|
|
652
|
+
for (const a of data) {
|
|
653
|
+
if (!predicate(a)) {
|
|
654
|
+
break;
|
|
655
|
+
}
|
|
656
|
+
result.push(a);
|
|
657
|
+
}
|
|
658
|
+
return result;
|
|
659
|
+
};
|
|
660
|
+
Arr2.dropWhile = (predicate) => (data) => {
|
|
661
|
+
let i = 0;
|
|
662
|
+
while (i < data.length && predicate(data[i])) {
|
|
663
|
+
i++;
|
|
664
|
+
}
|
|
665
|
+
return data.slice(i);
|
|
666
|
+
};
|
|
667
|
+
Arr2.scan = (initial, f) => (data) => {
|
|
668
|
+
const n = data.length;
|
|
669
|
+
const result = new Array(n);
|
|
670
|
+
let acc = initial;
|
|
671
|
+
for (let i = 0; i < n; i++) {
|
|
672
|
+
acc = f(acc, data[i]);
|
|
673
|
+
result[i] = acc;
|
|
674
|
+
}
|
|
675
|
+
return result;
|
|
676
|
+
};
|
|
677
|
+
Arr2.splitAt = (index) => (data) => {
|
|
678
|
+
const i = Math.max(0, index);
|
|
679
|
+
return [data.slice(0, i), data.slice(i)];
|
|
680
|
+
};
|
|
681
|
+
Arr2.partitionMaybe = (f) => (data) => {
|
|
682
|
+
const failures = [];
|
|
683
|
+
const successes = [];
|
|
684
|
+
for (let i = 0; i < data.length; i++) {
|
|
685
|
+
const res = f(data[i]);
|
|
686
|
+
if (res.kind === "Some") {
|
|
687
|
+
successes.push(res.value);
|
|
688
|
+
} else {
|
|
689
|
+
failures.push(data[i]);
|
|
690
|
+
}
|
|
691
|
+
}
|
|
692
|
+
return [failures, successes];
|
|
693
|
+
};
|
|
694
|
+
Arr2.at = (index) => (data) => {
|
|
695
|
+
const targetIndex = index < 0 ? data.length + index : index;
|
|
696
|
+
if (targetIndex < 0 || targetIndex >= data.length) {
|
|
697
|
+
return Maybe.make.none();
|
|
698
|
+
}
|
|
699
|
+
return Maybe.make.some(data[targetIndex]);
|
|
700
|
+
};
|
|
701
|
+
Arr2.findMap = (f) => (data) => {
|
|
702
|
+
for (let i = 0; i < data.length; i++) {
|
|
703
|
+
const res = f(data[i]);
|
|
704
|
+
if (res.kind === "Some") {
|
|
705
|
+
return res;
|
|
706
|
+
}
|
|
707
|
+
}
|
|
708
|
+
return Maybe.make.none();
|
|
709
|
+
};
|
|
710
|
+
Arr2.indexBy = (keyFn) => (data) => {
|
|
711
|
+
const map2 = new globalThis.Map();
|
|
712
|
+
for (let i = 0; i < data.length; i++) {
|
|
713
|
+
map2.set(keyFn(data[i]), data[i]);
|
|
714
|
+
}
|
|
715
|
+
return map2;
|
|
716
|
+
};
|
|
717
|
+
Arr2.frequencies = (data) => {
|
|
718
|
+
const map2 = new globalThis.Map();
|
|
719
|
+
for (let i = 0; i < data.length; i++) {
|
|
720
|
+
const item = data[i];
|
|
721
|
+
map2.set(item, (map2.get(item) ?? 0) + 1);
|
|
722
|
+
}
|
|
723
|
+
return map2;
|
|
724
|
+
};
|
|
725
|
+
Arr2.chunkBy = (keyFn) => (data) => {
|
|
726
|
+
if (data.length === 0) {
|
|
727
|
+
return [];
|
|
728
|
+
}
|
|
729
|
+
const result = [];
|
|
730
|
+
let currentChunk = [data[0]];
|
|
731
|
+
let currentKey = keyFn(data[0]);
|
|
732
|
+
for (let i = 1; i < data.length; i++) {
|
|
733
|
+
const item = data[i];
|
|
734
|
+
const key = keyFn(item);
|
|
735
|
+
if (Object.is(key, currentKey)) {
|
|
736
|
+
currentChunk.push(item);
|
|
737
|
+
} else {
|
|
738
|
+
result.push(currentChunk);
|
|
739
|
+
currentChunk = [item];
|
|
740
|
+
currentKey = key;
|
|
741
|
+
}
|
|
742
|
+
}
|
|
743
|
+
result.push(currentChunk);
|
|
744
|
+
return result;
|
|
745
|
+
};
|
|
746
|
+
Arr2.dedupeAdjacent = (eq = (a, b) => Object.is(a, b)) => (data) => {
|
|
747
|
+
if (data.length === 0) {
|
|
748
|
+
return [];
|
|
749
|
+
}
|
|
750
|
+
const result = [data[0]];
|
|
751
|
+
for (let i = 1; i < data.length; i++) {
|
|
752
|
+
if (!eq(data[i], result[result.length - 1])) {
|
|
753
|
+
result.push(data[i]);
|
|
754
|
+
}
|
|
755
|
+
}
|
|
756
|
+
return result;
|
|
757
|
+
};
|
|
758
|
+
Arr2.windowed = (size2, options) => (data) => {
|
|
759
|
+
const step = options?.step ?? 1;
|
|
760
|
+
if (size2 <= 0 || step <= 0 || data.length < size2) {
|
|
761
|
+
return [];
|
|
762
|
+
}
|
|
763
|
+
const result = [];
|
|
764
|
+
for (let i = 0; i <= data.length - size2; i += step) {
|
|
765
|
+
result.push(data.slice(i, i + size2));
|
|
766
|
+
}
|
|
767
|
+
return result;
|
|
768
|
+
};
|
|
769
|
+
Arr2.unfold = (initial, f) => {
|
|
770
|
+
const result = [];
|
|
771
|
+
let currentState = initial;
|
|
772
|
+
while (true) {
|
|
773
|
+
const next = f(currentState);
|
|
774
|
+
if (next.kind === "None") {
|
|
775
|
+
break;
|
|
776
|
+
}
|
|
777
|
+
const [item, nextState] = next.value;
|
|
778
|
+
result.push(item);
|
|
779
|
+
currentState = nextState;
|
|
780
|
+
}
|
|
781
|
+
return result;
|
|
782
|
+
};
|
|
783
|
+
Arr2.NonEmpty = ArrNonEmpty;
|
|
784
|
+
})(Arr || (Arr = {}));
|
|
785
|
+
|
|
786
|
+
// src/Data/BigNum.ts
|
|
787
|
+
var BigNum;
|
|
788
|
+
((BigNum2) => {
|
|
789
|
+
let from;
|
|
790
|
+
((from2) => {
|
|
791
|
+
from2.string = (s) => {
|
|
792
|
+
try {
|
|
793
|
+
if (s.trim() === "") {
|
|
794
|
+
return Maybe.make.none();
|
|
795
|
+
}
|
|
796
|
+
return Maybe.make.some(BigInt(s));
|
|
797
|
+
} catch {
|
|
798
|
+
return Maybe.make.none();
|
|
799
|
+
}
|
|
800
|
+
};
|
|
801
|
+
from2.number = (n) => {
|
|
802
|
+
if (!Number.isInteger(n) || n < Number.MIN_SAFE_INTEGER || n > Number.MAX_SAFE_INTEGER) {
|
|
803
|
+
return Maybe.make.none();
|
|
804
|
+
}
|
|
805
|
+
return Maybe.make.some(BigInt(n));
|
|
806
|
+
};
|
|
807
|
+
})(from = BigNum2.from || (BigNum2.from = {}));
|
|
808
|
+
let to;
|
|
809
|
+
((to2) => {
|
|
810
|
+
to2.number = (b) => {
|
|
811
|
+
if (b < BigInt(Number.MIN_SAFE_INTEGER) || b > BigInt(Number.MAX_SAFE_INTEGER)) {
|
|
812
|
+
return Maybe.make.none();
|
|
813
|
+
}
|
|
814
|
+
return Maybe.make.some(Number(b));
|
|
815
|
+
};
|
|
816
|
+
})(to = BigNum2.to || (BigNum2.to = {}));
|
|
817
|
+
BigNum2.add = (b) => (a) => a + b;
|
|
818
|
+
BigNum2.sub = (b) => (a) => a - b;
|
|
819
|
+
BigNum2.mul = (b) => (a) => a * b;
|
|
820
|
+
BigNum2.div = (b) => (a) => b === 0n ? Maybe.make.none() : Maybe.make.some(a / b);
|
|
821
|
+
BigNum2.mod = (b) => (a) => b === 0n ? Maybe.make.none() : Maybe.make.some(a % b);
|
|
822
|
+
BigNum2.clamp = (min2, max2) => (a) => a < min2 ? min2 : a > max2 ? max2 : a;
|
|
823
|
+
BigNum2.inRange = (start, end) => (a) => a >= start && a < end;
|
|
824
|
+
BigNum2.abs = (a) => a < 0n ? -a : a;
|
|
825
|
+
BigNum2.min = (b) => (a) => a < b ? a : b;
|
|
826
|
+
BigNum2.max = (b) => (a) => a > b ? a : b;
|
|
827
|
+
})(BigNum || (BigNum = {}));
|
|
828
|
+
|
|
829
|
+
// src/Data/Dict.ts
|
|
830
|
+
var DictNonEmpty;
|
|
831
|
+
((DictNonEmpty2) => {
|
|
832
|
+
DictNonEmpty2.singleton = (key, value) => new globalThis.Map([[key, value]]);
|
|
833
|
+
let from;
|
|
834
|
+
((from2) => {
|
|
835
|
+
from2.Map = (m) => m.size > 0 ? Maybe.make.some(m) : Maybe.make.none();
|
|
836
|
+
})(from = DictNonEmpty2.from || (DictNonEmpty2.from = {}));
|
|
837
|
+
DictNonEmpty2.keys = (m) => Dict.keys(m);
|
|
838
|
+
DictNonEmpty2.values = (m) => Dict.values(m);
|
|
839
|
+
DictNonEmpty2.entries = (m) => Dict.entries(m);
|
|
840
|
+
DictNonEmpty2.reduce = (f) => (m) => (0, DictNonEmpty2.values)(m).reduce(f);
|
|
841
|
+
DictNonEmpty2.map = (f) => (m) => Dict.map(f)(m);
|
|
842
|
+
DictNonEmpty2.mapWithKey = (f) => (m) => Dict.mapWithKey(f)(m);
|
|
843
|
+
})(DictNonEmpty || (DictNonEmpty = {}));
|
|
844
|
+
var Dict;
|
|
845
|
+
((Dict2) => {
|
|
846
|
+
let is;
|
|
847
|
+
((is2) => {
|
|
848
|
+
is2.empty = (m) => m.size === 0;
|
|
849
|
+
is2.nonEmpty = (m) => m.size > 0;
|
|
850
|
+
})(is = Dict2.is || (Dict2.is = {}));
|
|
851
|
+
Dict2.empty = () => new globalThis.Map();
|
|
852
|
+
Dict2.singleton = (key, value) => new globalThis.Map([[key, value]]);
|
|
853
|
+
let from;
|
|
854
|
+
((from2) => {
|
|
855
|
+
from2.entries = (entries3) => new globalThis.Map(entries3);
|
|
856
|
+
from2.Record = (rec) => new globalThis.Map(Object.entries(rec));
|
|
857
|
+
})(from = Dict2.from || (Dict2.from = {}));
|
|
858
|
+
Dict2.groupBy = (keyFn) => (items) => {
|
|
859
|
+
const result = new globalThis.Map();
|
|
860
|
+
for (const item of items) {
|
|
861
|
+
const key = keyFn(item);
|
|
862
|
+
const arr = result.get(key);
|
|
863
|
+
if (arr !== void 0) {
|
|
864
|
+
arr.push(item);
|
|
865
|
+
} else {
|
|
866
|
+
result.set(key, [item]);
|
|
867
|
+
}
|
|
868
|
+
}
|
|
869
|
+
return result;
|
|
870
|
+
};
|
|
871
|
+
Dict2.has = (key) => (m) => m.has(key);
|
|
872
|
+
Dict2.lookup = (key) => (m) => m.has(key) ? Maybe.make.some(m.get(key)) : Maybe.make.none();
|
|
873
|
+
Dict2.size = (m) => m.size;
|
|
874
|
+
Dict2.keys = (m) => [...m.keys()];
|
|
875
|
+
Dict2.values = (m) => [...m.values()];
|
|
876
|
+
Dict2.entries = (m) => [...m.entries()];
|
|
877
|
+
Dict2.insert = (key, value) => (m) => {
|
|
878
|
+
const result = new globalThis.Map(m);
|
|
879
|
+
result.set(key, value);
|
|
880
|
+
return result;
|
|
881
|
+
};
|
|
882
|
+
Dict2.remove = (key) => (m) => {
|
|
883
|
+
if (!m.has(key)) {
|
|
884
|
+
return m;
|
|
885
|
+
}
|
|
886
|
+
const result = new globalThis.Map(m);
|
|
887
|
+
result.delete(key);
|
|
888
|
+
return result;
|
|
889
|
+
};
|
|
890
|
+
Dict2.upsert = (key, f) => (m) => {
|
|
891
|
+
const result = new globalThis.Map(m);
|
|
892
|
+
result.set(key, f((0, Dict2.lookup)(key)(m)));
|
|
893
|
+
return result;
|
|
894
|
+
};
|
|
895
|
+
Dict2.map = (f) => (m) => {
|
|
896
|
+
const result = new globalThis.Map();
|
|
897
|
+
for (const [k, v] of m) {
|
|
898
|
+
result.set(k, f(v));
|
|
899
|
+
}
|
|
900
|
+
return result;
|
|
901
|
+
};
|
|
902
|
+
Dict2.mapWithKey = (f) => (m) => {
|
|
903
|
+
const result = new globalThis.Map();
|
|
904
|
+
for (const [k, v] of m) {
|
|
905
|
+
result.set(k, f(k, v));
|
|
906
|
+
}
|
|
907
|
+
return result;
|
|
908
|
+
};
|
|
909
|
+
Dict2.filter = (predicate) => (m) => {
|
|
910
|
+
const result = new globalThis.Map();
|
|
911
|
+
for (const [k, v] of m) {
|
|
912
|
+
if (predicate(v)) {
|
|
913
|
+
result.set(k, v);
|
|
914
|
+
}
|
|
915
|
+
}
|
|
916
|
+
return result;
|
|
917
|
+
};
|
|
918
|
+
Dict2.filterWithKey = (predicate) => (m) => {
|
|
919
|
+
const result = new globalThis.Map();
|
|
920
|
+
for (const [k, v] of m) {
|
|
921
|
+
if (predicate(k, v)) {
|
|
922
|
+
result.set(k, v);
|
|
923
|
+
}
|
|
924
|
+
}
|
|
925
|
+
return result;
|
|
926
|
+
};
|
|
927
|
+
Dict2.compact = (m) => {
|
|
928
|
+
const result = new globalThis.Map();
|
|
929
|
+
for (const [k, v] of m) {
|
|
930
|
+
if (v.kind === "Some") {
|
|
931
|
+
result.set(k, v.value);
|
|
932
|
+
}
|
|
933
|
+
}
|
|
934
|
+
return result;
|
|
935
|
+
};
|
|
936
|
+
Dict2.filterMap = (f) => (m) => {
|
|
937
|
+
const result = new globalThis.Map();
|
|
938
|
+
for (const [key, value] of m) {
|
|
939
|
+
const mapped = f(value);
|
|
940
|
+
if (mapped.kind === "Some") {
|
|
941
|
+
result.set(key, mapped.value);
|
|
942
|
+
}
|
|
943
|
+
}
|
|
944
|
+
return result;
|
|
945
|
+
};
|
|
946
|
+
Dict2.union = (other) => (m) => {
|
|
947
|
+
const result = new globalThis.Map(m);
|
|
948
|
+
for (const [k, v] of other) {
|
|
949
|
+
result.set(k, v);
|
|
950
|
+
}
|
|
951
|
+
return result;
|
|
952
|
+
};
|
|
953
|
+
Dict2.intersection = (other) => (m) => {
|
|
954
|
+
const result = new globalThis.Map();
|
|
955
|
+
for (const [k, v] of m) {
|
|
956
|
+
if (other.has(k)) {
|
|
957
|
+
result.set(k, v);
|
|
958
|
+
}
|
|
959
|
+
}
|
|
960
|
+
return result;
|
|
961
|
+
};
|
|
962
|
+
Dict2.difference = (other) => (m) => {
|
|
963
|
+
const result = new globalThis.Map();
|
|
964
|
+
for (const [k, v] of m) {
|
|
965
|
+
if (!other.has(k)) {
|
|
966
|
+
result.set(k, v);
|
|
967
|
+
}
|
|
968
|
+
}
|
|
969
|
+
return result;
|
|
970
|
+
};
|
|
971
|
+
Dict2.reduce = (init, f) => (m) => {
|
|
972
|
+
let acc = init;
|
|
973
|
+
for (const v of m.values()) {
|
|
974
|
+
acc = f(acc, v);
|
|
975
|
+
}
|
|
976
|
+
return acc;
|
|
977
|
+
};
|
|
978
|
+
Dict2.reduceWithKey = (init, f) => (m) => {
|
|
979
|
+
let acc = init;
|
|
980
|
+
for (const [k, v] of m) {
|
|
981
|
+
acc = f(acc, v, k);
|
|
982
|
+
}
|
|
983
|
+
return acc;
|
|
984
|
+
};
|
|
985
|
+
function mergeWith(combine) {
|
|
986
|
+
return (arg1, arg2) => {
|
|
987
|
+
if (arg2 !== void 0) {
|
|
988
|
+
const first = arg1;
|
|
989
|
+
const second2 = arg2;
|
|
990
|
+
const res = new globalThis.Map(first);
|
|
991
|
+
for (const [k, v] of second2) {
|
|
992
|
+
if (res.has(k)) {
|
|
993
|
+
res.set(k, combine(res.get(k), v));
|
|
994
|
+
} else {
|
|
995
|
+
res.set(k, v);
|
|
996
|
+
}
|
|
997
|
+
}
|
|
998
|
+
return res;
|
|
999
|
+
}
|
|
1000
|
+
const second = arg1;
|
|
1001
|
+
return (first) => {
|
|
1002
|
+
const res = new globalThis.Map(first);
|
|
1003
|
+
for (const [k, v] of second) {
|
|
1004
|
+
if (res.has(k)) {
|
|
1005
|
+
res.set(k, combine(res.get(k), v));
|
|
1006
|
+
} else {
|
|
1007
|
+
res.set(k, v);
|
|
1008
|
+
}
|
|
1009
|
+
}
|
|
1010
|
+
return res;
|
|
1011
|
+
};
|
|
1012
|
+
};
|
|
1013
|
+
}
|
|
1014
|
+
Dict2.mergeWith = mergeWith;
|
|
1015
|
+
let to;
|
|
1016
|
+
((to2) => {
|
|
1017
|
+
to2.Record = (m) => Object.fromEntries(m);
|
|
1018
|
+
})(to = Dict2.to || (Dict2.to = {}));
|
|
1019
|
+
Dict2.mapEntries = (f) => (data) => {
|
|
1020
|
+
const res = new globalThis.Map();
|
|
1021
|
+
for (const [k, v] of data) {
|
|
1022
|
+
const [nk, nv] = f(k, v);
|
|
1023
|
+
res.set(nk, nv);
|
|
1024
|
+
}
|
|
1025
|
+
return res;
|
|
1026
|
+
};
|
|
1027
|
+
Dict2.mapKeys = (f) => (data) => {
|
|
1028
|
+
const res = new globalThis.Map();
|
|
1029
|
+
for (const [k, v] of data) {
|
|
1030
|
+
res.set(f(k), v);
|
|
1031
|
+
}
|
|
1032
|
+
return res;
|
|
1033
|
+
};
|
|
1034
|
+
Dict2.NonEmpty = DictNonEmpty;
|
|
1035
|
+
})(Dict || (Dict = {}));
|
|
1036
|
+
|
|
1037
|
+
// src/Data/Json.ts
|
|
1038
|
+
var isSyntaxError = (err) => typeof err === "object" && err !== null && "name" in err && err.name === "SyntaxError";
|
|
1039
|
+
var isTypeError = (err) => typeof err === "object" && err !== null && "name" in err && err.name === "TypeError";
|
|
1040
|
+
var Json;
|
|
1041
|
+
((Json2) => {
|
|
1042
|
+
Json2.parse = (text) => Result.tryCatch(() => JSON.parse(text), {
|
|
1043
|
+
onError: (err) => isSyntaxError(err) ? err : new SyntaxError(String(err))
|
|
1044
|
+
});
|
|
1045
|
+
Json2.stringify = (value, replacer, space) => Result.tryCatch(() => JSON.stringify(value, replacer, space), {
|
|
1046
|
+
onError: (err) => isTypeError(err) ? err : new TypeError(String(err))
|
|
1047
|
+
});
|
|
1048
|
+
})(Json || (Json = {}));
|
|
1049
|
+
|
|
1050
|
+
// src/Data/Num.ts
|
|
1051
|
+
var Num;
|
|
1052
|
+
((Num2) => {
|
|
1053
|
+
let is;
|
|
1054
|
+
((is2) => {
|
|
1055
|
+
is2.zero = (n) => n === 0;
|
|
1056
|
+
is2.integer = (n) => Number.isInteger(n);
|
|
1057
|
+
is2.float = (n) => Number.isFinite(n) && !Number.isInteger(n);
|
|
1058
|
+
is2.finite = (n) => Number.isFinite(n);
|
|
1059
|
+
is2.nan = (n) => Number.isNaN(n);
|
|
1060
|
+
is2.even = (n) => Number.isInteger(n) && n % 2 === 0;
|
|
1061
|
+
is2.odd = (n) => Number.isInteger(n) && n % 2 !== 0;
|
|
1062
|
+
is2.positive = (n) => n > 0;
|
|
1063
|
+
is2.negative = (n) => n < 0;
|
|
1064
|
+
})(is = Num2.is || (Num2.is = {}));
|
|
1065
|
+
Num2.range = (from, to, step = 1) => {
|
|
1066
|
+
if (step <= 0 || from > to) {
|
|
1067
|
+
return [];
|
|
1068
|
+
}
|
|
1069
|
+
const count = Math.floor((to - from) / step) + 1;
|
|
1070
|
+
const result = new Array(count);
|
|
1071
|
+
for (let i = 0; i < count; i++) {
|
|
1072
|
+
result[i] = from + i * step;
|
|
1073
|
+
}
|
|
1074
|
+
return result;
|
|
1075
|
+
};
|
|
1076
|
+
Num2.clamp = (min2, max2) => (n) => Math.min(Math.max(n, min2), max2);
|
|
1077
|
+
Num2.between = (min2, max2) => (n) => n >= min2 && n <= max2;
|
|
1078
|
+
Num2.inRange = (start, end) => (n) => n >= start && n < end;
|
|
1079
|
+
Num2.parse = (s) => {
|
|
1080
|
+
if (s.trim() === "") {
|
|
1081
|
+
return Maybe.make.none();
|
|
1082
|
+
}
|
|
1083
|
+
const n = Number(s);
|
|
1084
|
+
return isNaN(n) ? Maybe.make.none() : Maybe.make.some(n);
|
|
1085
|
+
};
|
|
1086
|
+
Num2.add = (b) => (a) => a + b;
|
|
1087
|
+
Num2.subtract = (b) => (a) => a - b;
|
|
1088
|
+
Num2.multiply = (b) => (a) => a * b;
|
|
1089
|
+
Num2.divide = (b) => (a) => b === 0 ? Maybe.make.none() : Maybe.make.some(a / b);
|
|
1090
|
+
Num2.abs = (n) => Math.abs(n);
|
|
1091
|
+
Num2.negate = (n) => -n;
|
|
1092
|
+
Num2.round = (n) => Math.round(n);
|
|
1093
|
+
Num2.floor = (n) => Math.floor(n);
|
|
1094
|
+
Num2.ceil = (n) => Math.ceil(n);
|
|
1095
|
+
Num2.remainder = (divisor) => (n) => divisor === 0 ? Maybe.make.none() : Maybe.make.some(n % divisor);
|
|
1096
|
+
Num2.sum = (ns) => {
|
|
1097
|
+
let result = 0;
|
|
1098
|
+
for (let i = 0; i < ns.length; i++) {
|
|
1099
|
+
result += ns[i];
|
|
1100
|
+
}
|
|
1101
|
+
return result;
|
|
1102
|
+
};
|
|
1103
|
+
Num2.mean = (ns) => ns.length === 0 ? Maybe.make.none() : Maybe.make.some((0, Num2.sum)(ns) / ns.length);
|
|
1104
|
+
Num2.min = (ns) => {
|
|
1105
|
+
if (ns.length === 0) {
|
|
1106
|
+
return Maybe.make.none();
|
|
1107
|
+
}
|
|
1108
|
+
let [result] = ns;
|
|
1109
|
+
for (let i = 1; i < ns.length; i++) {
|
|
1110
|
+
if (ns[i] < result) {
|
|
1111
|
+
result = ns[i];
|
|
1112
|
+
}
|
|
1113
|
+
}
|
|
1114
|
+
return Maybe.make.some(result);
|
|
1115
|
+
};
|
|
1116
|
+
Num2.max = (ns) => {
|
|
1117
|
+
if (ns.length === 0) {
|
|
1118
|
+
return Maybe.make.none();
|
|
1119
|
+
}
|
|
1120
|
+
let [result] = ns;
|
|
1121
|
+
for (let i = 1; i < ns.length; i++) {
|
|
1122
|
+
if (ns[i] > result) {
|
|
1123
|
+
result = ns[i];
|
|
1124
|
+
}
|
|
1125
|
+
}
|
|
1126
|
+
return Maybe.make.some(result);
|
|
1127
|
+
};
|
|
1128
|
+
Num2.format = (options, locales) => (n) => !Number.isFinite(n) ? Maybe.make.none() : Maybe.make.some(new Intl.NumberFormat(locales, options).format(n));
|
|
1129
|
+
})(Num || (Num = {}));
|
|
1130
|
+
|
|
1131
|
+
// src/Data/Rec.ts
|
|
1132
|
+
var _isNonEmpty = (data) => Object.keys(data).length > 0;
|
|
1133
|
+
var RecMaybe;
|
|
1134
|
+
((RecMaybe2) => {
|
|
1135
|
+
RecMaybe2.traverse = (f) => (data) => {
|
|
1136
|
+
const recordKeys = Object.keys(data);
|
|
1137
|
+
const result = {};
|
|
1138
|
+
for (let i = 0; i < recordKeys.length; i++) {
|
|
1139
|
+
const key = recordKeys[i];
|
|
1140
|
+
const maybeVal = f(data[key]);
|
|
1141
|
+
if (maybeVal.kind === "None") {
|
|
1142
|
+
return maybeVal;
|
|
1143
|
+
}
|
|
1144
|
+
Object.defineProperty(result, key, { value: maybeVal.value, writable: true, enumerable: true, configurable: true });
|
|
1145
|
+
}
|
|
1146
|
+
return { kind: "Some", value: result };
|
|
1147
|
+
};
|
|
1148
|
+
RecMaybe2.sequence = (data) => (0, RecMaybe2.traverse)((a) => a)(data);
|
|
1149
|
+
})(RecMaybe || (RecMaybe = {}));
|
|
1150
|
+
var RecResult;
|
|
1151
|
+
((RecResult2) => {
|
|
1152
|
+
RecResult2.traverse = (f) => (data) => {
|
|
1153
|
+
const recordKeys = Object.keys(data);
|
|
1154
|
+
const result = {};
|
|
1155
|
+
for (let i = 0; i < recordKeys.length; i++) {
|
|
1156
|
+
const key = recordKeys[i];
|
|
1157
|
+
const res = f(data[key]);
|
|
1158
|
+
if (res.kind === "Err") {
|
|
1159
|
+
return res;
|
|
1160
|
+
}
|
|
1161
|
+
Object.defineProperty(result, key, { value: res.value, writable: true, enumerable: true, configurable: true });
|
|
1162
|
+
}
|
|
1163
|
+
return { kind: "Ok", value: result };
|
|
1164
|
+
};
|
|
1165
|
+
RecResult2.sequence = (data) => (0, RecResult2.traverse)((a) => a)(data);
|
|
1166
|
+
})(RecResult || (RecResult = {}));
|
|
1167
|
+
var RecNonEmpty;
|
|
1168
|
+
((RecNonEmpty2) => {
|
|
1169
|
+
RecNonEmpty2.singleton = (key, value) => ({ [key]: value });
|
|
1170
|
+
let from;
|
|
1171
|
+
((from2) => {
|
|
1172
|
+
from2.Record = (data) => _isNonEmpty(data) ? Maybe.make.some(data) : Maybe.make.none();
|
|
1173
|
+
})(from = RecNonEmpty2.from || (RecNonEmpty2.from = {}));
|
|
1174
|
+
RecNonEmpty2.keys = (data) => Rec.keys(data);
|
|
1175
|
+
RecNonEmpty2.values = (data) => Rec.values(data);
|
|
1176
|
+
RecNonEmpty2.entries = (data) => Rec.entries(data);
|
|
1177
|
+
RecNonEmpty2.reduce = (f) => (data) => (0, RecNonEmpty2.values)(data).reduce(f);
|
|
1178
|
+
RecNonEmpty2.map = (f) => (data) => Rec.map(f)(data);
|
|
1179
|
+
RecNonEmpty2.mapWithKey = (f) => (data) => Rec.mapWithKey(f)(data);
|
|
1180
|
+
})(RecNonEmpty || (RecNonEmpty = {}));
|
|
1181
|
+
var Rec;
|
|
1182
|
+
((Rec2) => {
|
|
1183
|
+
let is;
|
|
1184
|
+
((is2) => {
|
|
1185
|
+
is2.empty = (data) => Object.keys(data).length === 0;
|
|
1186
|
+
is2.nonEmpty = _isNonEmpty;
|
|
1187
|
+
})(is = Rec2.is || (Rec2.is = {}));
|
|
1188
|
+
Rec2.map = (f) => (data) => {
|
|
1189
|
+
const recordKeys = Object.keys(data);
|
|
1190
|
+
const recordValues = Object.values(data);
|
|
1191
|
+
const result = Object.create(Object.getPrototypeOf(data));
|
|
1192
|
+
for (let i = 0; i < recordKeys.length; i++) {
|
|
1193
|
+
const key = recordKeys[i];
|
|
1194
|
+
if (key === "__proto__") {
|
|
1195
|
+
Object.defineProperty(result, "__proto__", {
|
|
1196
|
+
value: f(recordValues[i]),
|
|
1197
|
+
writable: true,
|
|
1198
|
+
enumerable: true,
|
|
1199
|
+
configurable: true
|
|
1200
|
+
});
|
|
1201
|
+
} else {
|
|
1202
|
+
result[key] = f(recordValues[i]);
|
|
1203
|
+
}
|
|
1204
|
+
}
|
|
1205
|
+
return result;
|
|
1206
|
+
};
|
|
1207
|
+
Rec2.filterMap = (f) => (data) => {
|
|
1208
|
+
const recordKeys = Object.keys(data);
|
|
1209
|
+
const recordValues = Object.values(data);
|
|
1210
|
+
const result = Object.create(Object.getPrototypeOf(data));
|
|
1211
|
+
for (let i = 0; i < recordKeys.length; i++) {
|
|
1212
|
+
const maybeVal = f(recordValues[i]);
|
|
1213
|
+
if (maybeVal.kind === "Some") {
|
|
1214
|
+
Object.defineProperty(result, recordKeys[i], {
|
|
1215
|
+
value: maybeVal.value,
|
|
1216
|
+
writable: true,
|
|
1217
|
+
enumerable: true,
|
|
1218
|
+
configurable: true
|
|
1219
|
+
});
|
|
1220
|
+
}
|
|
1221
|
+
}
|
|
1222
|
+
return result;
|
|
1223
|
+
};
|
|
1224
|
+
Rec2.mapWithKey = (f) => (data) => {
|
|
1225
|
+
const recordKeys = Object.keys(data);
|
|
1226
|
+
const recordValues = Object.values(data);
|
|
1227
|
+
const result = Object.create(Object.getPrototypeOf(data));
|
|
1228
|
+
for (let i = 0; i < recordKeys.length; i++) {
|
|
1229
|
+
const key = recordKeys[i];
|
|
1230
|
+
if (key === "__proto__") {
|
|
1231
|
+
Object.defineProperty(result, "__proto__", {
|
|
1232
|
+
value: f(key, recordValues[i]),
|
|
1233
|
+
writable: true,
|
|
1234
|
+
enumerable: true,
|
|
1235
|
+
configurable: true
|
|
1236
|
+
});
|
|
1237
|
+
} else {
|
|
1238
|
+
result[key] = f(key, recordValues[i]);
|
|
1239
|
+
}
|
|
1240
|
+
}
|
|
1241
|
+
return result;
|
|
1242
|
+
};
|
|
1243
|
+
Rec2.filter = (predicate) => (data) => {
|
|
1244
|
+
const recordKeys = Object.keys(data);
|
|
1245
|
+
const recordValues = Object.values(data);
|
|
1246
|
+
const result = Object.create(Object.getPrototypeOf(data));
|
|
1247
|
+
for (let i = 0; i < recordKeys.length; i++) {
|
|
1248
|
+
if (predicate(recordValues[i])) {
|
|
1249
|
+
Object.defineProperty(result, recordKeys[i], {
|
|
1250
|
+
value: recordValues[i],
|
|
1251
|
+
writable: true,
|
|
1252
|
+
enumerable: true,
|
|
1253
|
+
configurable: true
|
|
1254
|
+
});
|
|
1255
|
+
}
|
|
1256
|
+
}
|
|
1257
|
+
return result;
|
|
1258
|
+
};
|
|
1259
|
+
Rec2.filterWithKey = (predicate) => (data) => {
|
|
1260
|
+
const result = {};
|
|
1261
|
+
for (const [k, v] of Object.entries(data)) {
|
|
1262
|
+
if (predicate(k, v)) {
|
|
1263
|
+
Object.defineProperty(result, k, { value: v, writable: true, enumerable: true, configurable: true });
|
|
1264
|
+
}
|
|
1265
|
+
}
|
|
1266
|
+
return result;
|
|
1267
|
+
};
|
|
1268
|
+
Rec2.lookup = (key) => (data) => Object.hasOwn(data, key) ? { kind: "Some", value: data[key] } : { kind: "None" };
|
|
1269
|
+
Rec2.keys = (data) => Object.keys(data);
|
|
1270
|
+
Rec2.values = (data) => Object.values(data);
|
|
1271
|
+
Rec2.entries = (data) => Object.entries(data);
|
|
1272
|
+
let from;
|
|
1273
|
+
((from2) => {
|
|
1274
|
+
from2.entries = (data) => Object.fromEntries(data);
|
|
1275
|
+
})(from = Rec2.from || (Rec2.from = {}));
|
|
1276
|
+
Rec2.groupBy = (keyFn) => (items) => {
|
|
1277
|
+
const result = {};
|
|
1278
|
+
for (const item of items) {
|
|
1279
|
+
const key = keyFn(item);
|
|
1280
|
+
if (Object.hasOwn(result, key)) {
|
|
1281
|
+
result[key].push(item);
|
|
1282
|
+
} else {
|
|
1283
|
+
Object.defineProperty(result, key, { value: [item], writable: true, enumerable: true, configurable: true });
|
|
1284
|
+
}
|
|
1285
|
+
}
|
|
1286
|
+
return result;
|
|
1287
|
+
};
|
|
1288
|
+
Rec2.pick = (...pickedKeys) => (data) => {
|
|
1289
|
+
const result = {};
|
|
1290
|
+
for (const key of pickedKeys) {
|
|
1291
|
+
if (Object.hasOwn(data, key)) {
|
|
1292
|
+
Object.defineProperty(result, key, { value: data[key], writable: true, enumerable: true, configurable: true });
|
|
1293
|
+
}
|
|
1294
|
+
}
|
|
1295
|
+
return result;
|
|
1296
|
+
};
|
|
1297
|
+
Rec2.omit = (...omittedKeys) => (data) => {
|
|
1298
|
+
const omitSet = new Set(omittedKeys);
|
|
1299
|
+
const result = {};
|
|
1300
|
+
for (const key of Object.keys(data)) {
|
|
1301
|
+
if (!omitSet.has(key)) {
|
|
1302
|
+
Object.defineProperty(result, key, {
|
|
1303
|
+
value: data[key],
|
|
1304
|
+
writable: true,
|
|
1305
|
+
enumerable: true,
|
|
1306
|
+
configurable: true
|
|
1307
|
+
});
|
|
1308
|
+
}
|
|
1309
|
+
}
|
|
1310
|
+
return result;
|
|
1311
|
+
};
|
|
1312
|
+
Rec2.merge = (other) => (data) => ({
|
|
1313
|
+
...data,
|
|
1314
|
+
...other
|
|
1315
|
+
});
|
|
1316
|
+
function mergeWith(combine) {
|
|
1317
|
+
return (arg1, arg2) => {
|
|
1318
|
+
if (arg2 !== void 0) {
|
|
1319
|
+
const first = arg1;
|
|
1320
|
+
const second2 = arg2;
|
|
1321
|
+
const result = { ...first };
|
|
1322
|
+
for (const [k, v] of Object.entries(second2)) {
|
|
1323
|
+
if (Object.hasOwn(result, k)) {
|
|
1324
|
+
result[k] = combine(result[k], v);
|
|
1325
|
+
} else {
|
|
1326
|
+
result[k] = v;
|
|
1327
|
+
}
|
|
1328
|
+
}
|
|
1329
|
+
return result;
|
|
1330
|
+
}
|
|
1331
|
+
const second = arg1;
|
|
1332
|
+
return (first) => {
|
|
1333
|
+
const result = { ...first };
|
|
1334
|
+
for (const [k, v] of Object.entries(second)) {
|
|
1335
|
+
if (Object.hasOwn(result, k)) {
|
|
1336
|
+
result[k] = combine(result[k], v);
|
|
1337
|
+
} else {
|
|
1338
|
+
result[k] = v;
|
|
1339
|
+
}
|
|
1340
|
+
}
|
|
1341
|
+
return result;
|
|
1342
|
+
};
|
|
1343
|
+
};
|
|
1344
|
+
}
|
|
1345
|
+
Rec2.mergeWith = mergeWith;
|
|
1346
|
+
Rec2.size = (data) => Object.keys(data).length;
|
|
1347
|
+
Rec2.mapKeys = (f) => (data) => {
|
|
1348
|
+
const result = {};
|
|
1349
|
+
for (const [k, v] of Object.entries(data)) {
|
|
1350
|
+
Object.defineProperty(result, f(k), { value: v, writable: true, enumerable: true, configurable: true });
|
|
1351
|
+
}
|
|
1352
|
+
return result;
|
|
1353
|
+
};
|
|
1354
|
+
Rec2.compact = (data) => {
|
|
1355
|
+
const result = {};
|
|
1356
|
+
for (const [k, v] of Object.entries(data)) {
|
|
1357
|
+
if (v.kind === "Some") {
|
|
1358
|
+
Object.defineProperty(result, k, { value: v.value, writable: true, enumerable: true, configurable: true });
|
|
1359
|
+
}
|
|
1360
|
+
}
|
|
1361
|
+
return result;
|
|
1362
|
+
};
|
|
1363
|
+
Rec2.mapEntries = (f) => (data) => {
|
|
1364
|
+
const result = {};
|
|
1365
|
+
for (const [k, v] of Object.entries(data)) {
|
|
1366
|
+
const [newKey, newVal] = f(k, v);
|
|
1367
|
+
Object.defineProperty(result, newKey, { value: newVal, writable: true, enumerable: true, configurable: true });
|
|
1368
|
+
}
|
|
1369
|
+
return result;
|
|
1370
|
+
};
|
|
1371
|
+
Rec2.updateIn = (path, f) => (data) => {
|
|
1372
|
+
const updateNode = (obj, keys2) => {
|
|
1373
|
+
const [head, ...tail] = keys2;
|
|
1374
|
+
if (tail.length === 0) {
|
|
1375
|
+
return { ...obj, [head]: f(obj?.[head]) };
|
|
1376
|
+
}
|
|
1377
|
+
const child = obj && typeof obj === "object" && head in obj ? obj[head] : {};
|
|
1378
|
+
return { ...obj, [head]: updateNode(child, tail) };
|
|
1379
|
+
};
|
|
1380
|
+
return updateNode(data, path);
|
|
1381
|
+
};
|
|
1382
|
+
let traverse;
|
|
1383
|
+
((traverse2) => {
|
|
1384
|
+
traverse2.Maybe = RecMaybe.traverse;
|
|
1385
|
+
traverse2.Result = RecResult.traverse;
|
|
1386
|
+
})(traverse = Rec2.traverse || (Rec2.traverse = {}));
|
|
1387
|
+
let sequence;
|
|
1388
|
+
((sequence2) => {
|
|
1389
|
+
sequence2.Maybe = RecMaybe.sequence;
|
|
1390
|
+
sequence2.Result = RecResult.sequence;
|
|
1391
|
+
})(sequence = Rec2.sequence || (Rec2.sequence = {}));
|
|
1392
|
+
Rec2.NonEmpty = RecNonEmpty;
|
|
1393
|
+
})(Rec || (Rec = {}));
|
|
1394
|
+
|
|
1395
|
+
// src/Data/Str.ts
|
|
1396
|
+
var StrNonEmpty;
|
|
1397
|
+
((StrNonEmpty2) => {
|
|
1398
|
+
let from;
|
|
1399
|
+
((from2) => {
|
|
1400
|
+
from2.String = (s) => s.length > 0 ? Maybe.make.some(s) : Maybe.make.none();
|
|
1401
|
+
})(from = StrNonEmpty2.from || (StrNonEmpty2.from = {}));
|
|
1402
|
+
})(StrNonEmpty || (StrNonEmpty = {}));
|
|
1403
|
+
var Str;
|
|
1404
|
+
((Str2) => {
|
|
1405
|
+
let is;
|
|
1406
|
+
((is2) => {
|
|
1407
|
+
is2.empty = (s) => s.length === 0;
|
|
1408
|
+
is2.nonEmpty = (s) => s.length > 0;
|
|
1409
|
+
})(is = Str2.is || (Str2.is = {}));
|
|
1410
|
+
Str2.split = (separator) => (s) => s.split(separator);
|
|
1411
|
+
Str2.trim = (s) => s.trim();
|
|
1412
|
+
Str2.includes = (substring) => (s) => s.includes(substring);
|
|
1413
|
+
Str2.replace = (pattern, replacement) => (s) => s.replace(pattern, replacement);
|
|
1414
|
+
Str2.replaceAll = (pattern, replacement) => (s) => s.replaceAll(pattern, replacement);
|
|
1415
|
+
Str2.startsWith = (prefix) => (s) => s.startsWith(prefix);
|
|
1416
|
+
Str2.endsWith = (suffix) => (s) => s.endsWith(suffix);
|
|
1417
|
+
Str2.toUpperCase = (s) => s.toUpperCase();
|
|
1418
|
+
Str2.toLowerCase = (s) => s.toLowerCase();
|
|
1419
|
+
Str2.capitalize = (s) => s.length === 0 ? "" : s.charAt(0).toUpperCase() + s.slice(1);
|
|
1420
|
+
Str2.lines = (s) => s.split(/\r?\n|\r/);
|
|
1421
|
+
Str2.words = (s) => s.trim().split(/\s+/).filter(Boolean);
|
|
1422
|
+
Str2.isBlank = (s) => s.trim().length === 0;
|
|
1423
|
+
Str2.length = (s) => s.length;
|
|
1424
|
+
Str2.slice = (start, end) => (s) => s.slice(start, end);
|
|
1425
|
+
Str2.padStart = (maxLength, fillString) => (s) => s.padStart(maxLength, fillString);
|
|
1426
|
+
Str2.padEnd = (maxLength, fillString) => (s) => s.padEnd(maxLength, fillString);
|
|
1427
|
+
Str2.parse = {
|
|
1428
|
+
/**
|
|
1429
|
+
* Parses a string as an integer (base 10). Returns `None` if the result is `NaN`.
|
|
1430
|
+
*
|
|
1431
|
+
* @example
|
|
1432
|
+
* ```ts
|
|
1433
|
+
* Str.parse.int("42"); // Some(42)
|
|
1434
|
+
* Str.parse.int("3.7"); // Some(3)
|
|
1435
|
+
* Str.parse.int("abc"); // None
|
|
1436
|
+
* ```
|
|
1437
|
+
*/
|
|
1438
|
+
int: (s) => {
|
|
1439
|
+
const n = parseInt(s, 10);
|
|
1440
|
+
return isNaN(n) ? Maybe.make.none() : Maybe.make.some(n);
|
|
1441
|
+
},
|
|
1442
|
+
/**
|
|
1443
|
+
* Parses a string as a floating-point number. Returns `None` if the result is `NaN`.
|
|
1444
|
+
*
|
|
1445
|
+
* @example
|
|
1446
|
+
* ```ts
|
|
1447
|
+
* Str.parse.float("3.14"); // Some(3.14)
|
|
1448
|
+
* Str.parse.float("42"); // Some(42)
|
|
1449
|
+
* Str.parse.float("abc"); // None
|
|
1450
|
+
* ```
|
|
1451
|
+
*/
|
|
1452
|
+
float: (s) => {
|
|
1453
|
+
const n = parseFloat(s);
|
|
1454
|
+
return isNaN(n) ? Maybe.make.none() : Maybe.make.some(n);
|
|
1455
|
+
}
|
|
1456
|
+
};
|
|
1457
|
+
Str2.parseJson = (s) => {
|
|
1458
|
+
try {
|
|
1459
|
+
return Result.make.ok(JSON.parse(s));
|
|
1460
|
+
} catch (error) {
|
|
1461
|
+
return Result.make.err(error);
|
|
1462
|
+
}
|
|
1463
|
+
};
|
|
1464
|
+
Str2.uncapitalize = (s) => s.length === 0 ? "" : s.charAt(0).toLowerCase() + s.slice(1);
|
|
1465
|
+
Str2.truncate = (options) => (s) => {
|
|
1466
|
+
const { length: targetLength, suffix = "..." } = options;
|
|
1467
|
+
if (s.length <= targetLength) {
|
|
1468
|
+
return s;
|
|
1469
|
+
}
|
|
1470
|
+
if (targetLength <= suffix.length) {
|
|
1471
|
+
return suffix.slice(0, targetLength);
|
|
1472
|
+
}
|
|
1473
|
+
return s.slice(0, targetLength - suffix.length) + suffix;
|
|
1474
|
+
};
|
|
1475
|
+
Str2.NonEmpty = StrNonEmpty;
|
|
1476
|
+
})(Str || (Str = {}));
|
|
1477
|
+
|
|
1478
|
+
// src/Data/Uniq.ts
|
|
1479
|
+
var UniqNonEmpty;
|
|
1480
|
+
((UniqNonEmpty2) => {
|
|
1481
|
+
UniqNonEmpty2.singleton = (item) => new globalThis.Set([item]);
|
|
1482
|
+
let from;
|
|
1483
|
+
((from2) => {
|
|
1484
|
+
from2.Set = (s) => s.size > 0 ? Maybe.make.some(s) : Maybe.make.none();
|
|
1485
|
+
})(from = UniqNonEmpty2.from || (UniqNonEmpty2.from = {}));
|
|
1486
|
+
UniqNonEmpty2.reduce = (f) => (s) => to.Array(s).reduce(f);
|
|
1487
|
+
UniqNonEmpty2.map = (f) => (s) => Uniq.map(f)(s);
|
|
1488
|
+
let to;
|
|
1489
|
+
((to2) => {
|
|
1490
|
+
to2.Array = (s) => Uniq.to.Array(s);
|
|
1491
|
+
})(to = UniqNonEmpty2.to || (UniqNonEmpty2.to = {}));
|
|
1492
|
+
})(UniqNonEmpty || (UniqNonEmpty = {}));
|
|
1493
|
+
var Uniq;
|
|
1494
|
+
((Uniq2) => {
|
|
1495
|
+
let is;
|
|
1496
|
+
((is2) => {
|
|
1497
|
+
is2.empty = (s) => s.size === 0;
|
|
1498
|
+
is2.nonEmpty = (s) => s.size > 0;
|
|
1499
|
+
})(is = Uniq2.is || (Uniq2.is = {}));
|
|
1500
|
+
Uniq2.empty = () => new globalThis.Set();
|
|
1501
|
+
Uniq2.singleton = (item) => new globalThis.Set([item]);
|
|
1502
|
+
let from;
|
|
1503
|
+
((from2) => {
|
|
1504
|
+
from2.Array = (arr) => new globalThis.Set(arr);
|
|
1505
|
+
})(from = Uniq2.from || (Uniq2.from = {}));
|
|
1506
|
+
Uniq2.has = (item) => (s) => s.has(item);
|
|
1507
|
+
Uniq2.size = (s) => s.size;
|
|
1508
|
+
Uniq2.isSubsetOf = (other) => (s) => {
|
|
1509
|
+
const set = s;
|
|
1510
|
+
if (typeof set.isSubsetOf === "function") {
|
|
1511
|
+
return set.isSubsetOf(other);
|
|
1512
|
+
}
|
|
1513
|
+
for (const item of s) {
|
|
1514
|
+
if (!other.has(item)) {
|
|
1515
|
+
return false;
|
|
1516
|
+
}
|
|
1517
|
+
}
|
|
1518
|
+
return true;
|
|
1519
|
+
};
|
|
1520
|
+
Uniq2.insert = (item) => (s) => {
|
|
1521
|
+
if (s.has(item)) {
|
|
1522
|
+
return s;
|
|
1523
|
+
}
|
|
1524
|
+
const result = new globalThis.Set(s);
|
|
1525
|
+
result.add(item);
|
|
1526
|
+
return result;
|
|
1527
|
+
};
|
|
1528
|
+
Uniq2.remove = (item) => (s) => {
|
|
1529
|
+
if (!s.has(item)) {
|
|
1530
|
+
return s;
|
|
1531
|
+
}
|
|
1532
|
+
const result = new globalThis.Set(s);
|
|
1533
|
+
result.delete(item);
|
|
1534
|
+
return result;
|
|
1535
|
+
};
|
|
1536
|
+
Uniq2.map = (f) => (s) => {
|
|
1537
|
+
const result = new globalThis.Set();
|
|
1538
|
+
for (const item of s) {
|
|
1539
|
+
result.add(f(item));
|
|
1540
|
+
}
|
|
1541
|
+
return result;
|
|
1542
|
+
};
|
|
1543
|
+
Uniq2.filter = (predicate) => (s) => {
|
|
1544
|
+
const result = new globalThis.Set();
|
|
1545
|
+
for (const item of s) {
|
|
1546
|
+
if (predicate(item)) {
|
|
1547
|
+
result.add(item);
|
|
1548
|
+
}
|
|
1549
|
+
}
|
|
1550
|
+
return result;
|
|
1551
|
+
};
|
|
1552
|
+
Uniq2.union = (other) => (s) => {
|
|
1553
|
+
const set = s;
|
|
1554
|
+
if (typeof set.union === "function") {
|
|
1555
|
+
return set.union(other);
|
|
1556
|
+
}
|
|
1557
|
+
const result = new globalThis.Set(s);
|
|
1558
|
+
for (const item of other) {
|
|
1559
|
+
result.add(item);
|
|
1560
|
+
}
|
|
1561
|
+
return result;
|
|
1562
|
+
};
|
|
1563
|
+
Uniq2.intersection = (other) => (s) => {
|
|
1564
|
+
const set = s;
|
|
1565
|
+
if (typeof set.intersection === "function") {
|
|
1566
|
+
return set.intersection(other);
|
|
1567
|
+
}
|
|
1568
|
+
const result = new globalThis.Set();
|
|
1569
|
+
for (const item of s) {
|
|
1570
|
+
if (other.has(item)) {
|
|
1571
|
+
result.add(item);
|
|
1572
|
+
}
|
|
1573
|
+
}
|
|
1574
|
+
return result;
|
|
1575
|
+
};
|
|
1576
|
+
Uniq2.difference = (other) => (s) => {
|
|
1577
|
+
const set = s;
|
|
1578
|
+
if (typeof set.difference === "function") {
|
|
1579
|
+
return set.difference(other);
|
|
1580
|
+
}
|
|
1581
|
+
const result = new globalThis.Set();
|
|
1582
|
+
for (const item of s) {
|
|
1583
|
+
if (!other.has(item)) {
|
|
1584
|
+
result.add(item);
|
|
1585
|
+
}
|
|
1586
|
+
}
|
|
1587
|
+
return result;
|
|
1588
|
+
};
|
|
1589
|
+
Uniq2.reduce = (init, f) => (s) => {
|
|
1590
|
+
let acc = init;
|
|
1591
|
+
for (const item of s) {
|
|
1592
|
+
acc = f(acc, item);
|
|
1593
|
+
}
|
|
1594
|
+
return acc;
|
|
1595
|
+
};
|
|
1596
|
+
let to;
|
|
1597
|
+
((to2) => {
|
|
1598
|
+
to2.Array = (s) => [...s];
|
|
1599
|
+
})(to = Uniq2.to || (Uniq2.to = {}));
|
|
1600
|
+
Uniq2.NonEmpty = UniqNonEmpty;
|
|
1601
|
+
})(Uniq || (Uniq = {}));
|
|
1602
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
1603
|
+
0 && (module.exports = {
|
|
1604
|
+
Arr,
|
|
1605
|
+
BigNum,
|
|
1606
|
+
Dict,
|
|
1607
|
+
Json,
|
|
1608
|
+
Num,
|
|
1609
|
+
Rec,
|
|
1610
|
+
Str,
|
|
1611
|
+
Uniq
|
|
1612
|
+
});
|