@nlozgachev/pipelined 0.13.0 → 0.14.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/{Task-ChKyH0pF.d.mts → Task-Bd3gXPRQ.d.mts} +1 -1
- package/dist/{Task-BB8Wmc1J.d.ts → Task-BjAkkD6t.d.ts} +1 -1
- package/dist/chunk-4TXC322E.mjs +136 -0
- package/dist/chunk-BYWKZLHM.mjs +10 -0
- package/dist/chunk-FAZN3IWZ.mjs +554 -0
- package/dist/chunk-UV2HMF2A.mjs +514 -0
- package/dist/composition.mjs +29 -106
- package/dist/core.d.mts +2 -2
- package/dist/core.d.ts +2 -2
- package/dist/core.mjs +16 -491
- package/dist/index.d.mts +6 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +1421 -0
- package/dist/index.mjs +120 -0
- package/dist/types.mjs +3 -7
- package/dist/utils.d.mts +1 -1
- package/dist/utils.d.ts +1 -1
- package/dist/utils.mjs +9 -544
- package/package.json +2 -1
|
@@ -674,4 +674,4 @@ declare namespace Task {
|
|
|
674
674
|
const timeout: <E>(ms: number, onTimeout: () => E) => <A>(task: Task<A>) => Task<Result<E, A>>;
|
|
675
675
|
}
|
|
676
676
|
|
|
677
|
-
export { Deferred as D, type Err as E, type None as N,
|
|
677
|
+
export { Deferred as D, type Err as E, type None as N, type Ok as O, Result as R, type Some as S, Task as T, type WithValue as W, Option as a, type WithLog as b, type WithKind as c, type WithError as d, type WithErrors as e, type WithFirst as f, type WithSecond as g };
|
|
@@ -674,4 +674,4 @@ declare namespace Task {
|
|
|
674
674
|
const timeout: <E>(ms: number, onTimeout: () => E) => <A>(task: Task<A>) => Task<Result<E, A>>;
|
|
675
675
|
}
|
|
676
676
|
|
|
677
|
-
export { Deferred as D, type Err as E, type None as N,
|
|
677
|
+
export { Deferred as D, type Err as E, type None as N, type Ok as O, Result as R, type Some as S, Task as T, type WithValue as W, Option as a, type WithLog as b, type WithKind as c, type WithError as d, type WithErrors as e, type WithFirst as f, type WithSecond as g };
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
// src/Composition/compose.ts
|
|
2
|
+
function compose(...fns) {
|
|
3
|
+
return (arg) => fns.reduceRight((acc, fn) => fn(acc), arg);
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
// src/Composition/converge.ts
|
|
7
|
+
function converge(f, transformers) {
|
|
8
|
+
return (a) => f(...transformers.map((t) => t(a)));
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
// src/Composition/curry.ts
|
|
12
|
+
var curry = (f) => (a) => (b) => f(a, b);
|
|
13
|
+
var curry3 = (f) => (a) => (b) => (c) => f(a, b, c);
|
|
14
|
+
var curry4 = (f) => (a) => (b) => (c) => (d) => f(a, b, c, d);
|
|
15
|
+
|
|
16
|
+
// src/Composition/flip.ts
|
|
17
|
+
var flip = (f) => (b) => (a) => f(a)(b);
|
|
18
|
+
|
|
19
|
+
// src/Composition/flow.ts
|
|
20
|
+
function flow(...fns) {
|
|
21
|
+
return (...args) => {
|
|
22
|
+
if (fns.length === 0) return args[0];
|
|
23
|
+
const [first, ...rest] = fns;
|
|
24
|
+
return rest.reduce((acc, fn) => fn(acc), first(...args));
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// src/Composition/fn.ts
|
|
29
|
+
var identity = (a) => a;
|
|
30
|
+
var constant = (a) => () => a;
|
|
31
|
+
var constTrue = () => true;
|
|
32
|
+
var constFalse = () => false;
|
|
33
|
+
var constNull = () => null;
|
|
34
|
+
var constUndefined = () => void 0;
|
|
35
|
+
var constVoid = () => {
|
|
36
|
+
};
|
|
37
|
+
var and = (p1, p2) => (...args) => p1(...args) && p2(...args);
|
|
38
|
+
var or = (p1, p2) => (...args) => p1(...args) || p2(...args);
|
|
39
|
+
var once = (f) => {
|
|
40
|
+
let called = false;
|
|
41
|
+
let result;
|
|
42
|
+
return () => {
|
|
43
|
+
if (!called) {
|
|
44
|
+
result = f();
|
|
45
|
+
called = true;
|
|
46
|
+
}
|
|
47
|
+
return result;
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
// src/Composition/juxt.ts
|
|
52
|
+
function juxt(fns) {
|
|
53
|
+
return (a) => fns.map((f) => f(a));
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// src/Composition/memoize.ts
|
|
57
|
+
var memoize = (f, keyFn = (a) => a) => {
|
|
58
|
+
const cache = /* @__PURE__ */ new Map();
|
|
59
|
+
return (a) => {
|
|
60
|
+
const key = keyFn(a);
|
|
61
|
+
if (cache.has(key)) {
|
|
62
|
+
return cache.get(key);
|
|
63
|
+
}
|
|
64
|
+
const result = f(a);
|
|
65
|
+
cache.set(key, result);
|
|
66
|
+
return result;
|
|
67
|
+
};
|
|
68
|
+
};
|
|
69
|
+
var memoizeWeak = (f) => {
|
|
70
|
+
const cache = /* @__PURE__ */ new WeakMap();
|
|
71
|
+
return (a) => {
|
|
72
|
+
if (cache.has(a)) {
|
|
73
|
+
return cache.get(a);
|
|
74
|
+
}
|
|
75
|
+
const result = f(a);
|
|
76
|
+
cache.set(a, result);
|
|
77
|
+
return result;
|
|
78
|
+
};
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
// src/Composition/not.ts
|
|
82
|
+
var not = (predicate) => (...args) => !predicate(...args);
|
|
83
|
+
|
|
84
|
+
// src/Composition/on.ts
|
|
85
|
+
var on = (f, g) => (a, b) => f(g(a), g(b));
|
|
86
|
+
|
|
87
|
+
// src/Composition/pipe.ts
|
|
88
|
+
function pipe(a, ...fns) {
|
|
89
|
+
return fns.reduce((acc, fn) => fn(acc), a);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// src/Composition/tap.ts
|
|
93
|
+
var tap = (f) => (a) => {
|
|
94
|
+
f(a);
|
|
95
|
+
return a;
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
// src/Composition/uncurry.ts
|
|
99
|
+
function uncurry(f) {
|
|
100
|
+
return (...args) => {
|
|
101
|
+
const inner = f(...args.slice(0, f.length));
|
|
102
|
+
return inner.length === 0 ? inner() : inner(...args.slice(f.length));
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
var uncurry3 = (f) => (a, b, c) => f(a)(b)(c);
|
|
106
|
+
var uncurry4 = (f) => (a, b, c, d) => f(a)(b)(c)(d);
|
|
107
|
+
|
|
108
|
+
export {
|
|
109
|
+
compose,
|
|
110
|
+
converge,
|
|
111
|
+
curry,
|
|
112
|
+
curry3,
|
|
113
|
+
curry4,
|
|
114
|
+
flip,
|
|
115
|
+
flow,
|
|
116
|
+
identity,
|
|
117
|
+
constant,
|
|
118
|
+
constTrue,
|
|
119
|
+
constFalse,
|
|
120
|
+
constNull,
|
|
121
|
+
constUndefined,
|
|
122
|
+
constVoid,
|
|
123
|
+
and,
|
|
124
|
+
or,
|
|
125
|
+
once,
|
|
126
|
+
juxt,
|
|
127
|
+
memoize,
|
|
128
|
+
memoizeWeak,
|
|
129
|
+
not,
|
|
130
|
+
on,
|
|
131
|
+
pipe,
|
|
132
|
+
tap,
|
|
133
|
+
uncurry,
|
|
134
|
+
uncurry3,
|
|
135
|
+
uncurry4
|
|
136
|
+
};
|
|
@@ -0,0 +1,554 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Deferred,
|
|
3
|
+
Option,
|
|
4
|
+
Result,
|
|
5
|
+
Task
|
|
6
|
+
} from "./chunk-QPTGO5AS.mjs";
|
|
7
|
+
import {
|
|
8
|
+
isNonEmptyList
|
|
9
|
+
} from "./chunk-DBIC62UV.mjs";
|
|
10
|
+
|
|
11
|
+
// src/Utils/Arr.ts
|
|
12
|
+
var Arr;
|
|
13
|
+
((Arr2) => {
|
|
14
|
+
Arr2.head = (data) => data.length > 0 ? Option.some(data[0]) : Option.none();
|
|
15
|
+
Arr2.last = (data) => data.length > 0 ? Option.some(data[data.length - 1]) : Option.none();
|
|
16
|
+
Arr2.tail = (data) => data.length > 0 ? Option.some(data.slice(1)) : Option.none();
|
|
17
|
+
Arr2.init = (data) => data.length > 0 ? Option.some(data.slice(0, -1)) : Option.none();
|
|
18
|
+
Arr2.findFirst = (predicate) => (data) => {
|
|
19
|
+
const idx = data.findIndex(predicate);
|
|
20
|
+
return idx >= 0 ? Option.some(data[idx]) : Option.none();
|
|
21
|
+
};
|
|
22
|
+
Arr2.findLast = (predicate) => (data) => {
|
|
23
|
+
for (let i = data.length - 1; i >= 0; i--) {
|
|
24
|
+
if (predicate(data[i])) return Option.some(data[i]);
|
|
25
|
+
}
|
|
26
|
+
return Option.none();
|
|
27
|
+
};
|
|
28
|
+
Arr2.findIndex = (predicate) => (data) => {
|
|
29
|
+
const idx = data.findIndex(predicate);
|
|
30
|
+
return idx >= 0 ? Option.some(idx) : Option.none();
|
|
31
|
+
};
|
|
32
|
+
Arr2.map = (f) => (data) => {
|
|
33
|
+
const n = data.length;
|
|
34
|
+
const result = new Array(n);
|
|
35
|
+
for (let i = 0; i < n; i++) result[i] = f(data[i]);
|
|
36
|
+
return result;
|
|
37
|
+
};
|
|
38
|
+
Arr2.filter = (predicate) => (data) => {
|
|
39
|
+
const n = data.length;
|
|
40
|
+
const result = [];
|
|
41
|
+
for (let i = 0; i < n; i++) {
|
|
42
|
+
if (predicate(data[i])) result.push(data[i]);
|
|
43
|
+
}
|
|
44
|
+
return result;
|
|
45
|
+
};
|
|
46
|
+
Arr2.partition = (predicate) => (data) => {
|
|
47
|
+
const pass = [];
|
|
48
|
+
const fail = [];
|
|
49
|
+
for (const a of data) {
|
|
50
|
+
(predicate(a) ? pass : fail).push(a);
|
|
51
|
+
}
|
|
52
|
+
return [pass, fail];
|
|
53
|
+
};
|
|
54
|
+
Arr2.groupBy = (f) => (data) => {
|
|
55
|
+
const result = {};
|
|
56
|
+
for (const a of data) {
|
|
57
|
+
const key = f(a);
|
|
58
|
+
if (!result[key]) result[key] = [];
|
|
59
|
+
result[key].push(a);
|
|
60
|
+
}
|
|
61
|
+
return result;
|
|
62
|
+
};
|
|
63
|
+
Arr2.uniq = (data) => [
|
|
64
|
+
...new Set(data)
|
|
65
|
+
];
|
|
66
|
+
Arr2.uniqBy = (f) => (data) => {
|
|
67
|
+
const seen = /* @__PURE__ */ new Set();
|
|
68
|
+
const result = [];
|
|
69
|
+
for (const a of data) {
|
|
70
|
+
const key = f(a);
|
|
71
|
+
if (!seen.has(key)) {
|
|
72
|
+
seen.add(key);
|
|
73
|
+
result.push(a);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return result;
|
|
77
|
+
};
|
|
78
|
+
Arr2.sortBy = (compare) => (data) => [...data].sort(compare);
|
|
79
|
+
Arr2.zip = (other) => (data) => {
|
|
80
|
+
const len = Math.min(data.length, other.length);
|
|
81
|
+
const result = new Array(len);
|
|
82
|
+
for (let i = 0; i < len; i++) {
|
|
83
|
+
result[i] = [data[i], other[i]];
|
|
84
|
+
}
|
|
85
|
+
return result;
|
|
86
|
+
};
|
|
87
|
+
Arr2.zipWith = (f) => (other) => (data) => {
|
|
88
|
+
const len = Math.min(data.length, other.length);
|
|
89
|
+
const result = new Array(len);
|
|
90
|
+
for (let i = 0; i < len; i++) {
|
|
91
|
+
result[i] = f(data[i], other[i]);
|
|
92
|
+
}
|
|
93
|
+
return result;
|
|
94
|
+
};
|
|
95
|
+
Arr2.intersperse = (sep) => (data) => {
|
|
96
|
+
if (data.length <= 1) return data;
|
|
97
|
+
const result = [data[0]];
|
|
98
|
+
for (let i = 1; i < data.length; i++) {
|
|
99
|
+
result.push(sep, data[i]);
|
|
100
|
+
}
|
|
101
|
+
return result;
|
|
102
|
+
};
|
|
103
|
+
Arr2.chunksOf = (n) => (data) => {
|
|
104
|
+
if (n <= 0) return [];
|
|
105
|
+
const result = [];
|
|
106
|
+
for (let i = 0; i < data.length; i += n) {
|
|
107
|
+
result.push(data.slice(i, i + n));
|
|
108
|
+
}
|
|
109
|
+
return result;
|
|
110
|
+
};
|
|
111
|
+
Arr2.flatten = (data) => [].concat(...data);
|
|
112
|
+
Arr2.flatMap = (f) => (data) => {
|
|
113
|
+
const n = data.length;
|
|
114
|
+
const result = [];
|
|
115
|
+
for (let i = 0; i < n; i++) {
|
|
116
|
+
const chunk = f(data[i]);
|
|
117
|
+
const m = chunk.length;
|
|
118
|
+
for (let j = 0; j < m; j++) result.push(chunk[j]);
|
|
119
|
+
}
|
|
120
|
+
return result;
|
|
121
|
+
};
|
|
122
|
+
Arr2.reduce = (initial, f) => (data) => data.reduce(f, initial);
|
|
123
|
+
Arr2.traverse = (f) => (data) => {
|
|
124
|
+
const n = data.length;
|
|
125
|
+
const result = new Array(n);
|
|
126
|
+
for (let i = 0; i < n; i++) {
|
|
127
|
+
const mapped = f(data[i]);
|
|
128
|
+
if (mapped.kind === "None") return Option.none();
|
|
129
|
+
result[i] = mapped.value;
|
|
130
|
+
}
|
|
131
|
+
return Option.some(result);
|
|
132
|
+
};
|
|
133
|
+
Arr2.traverseResult = (f) => (data) => {
|
|
134
|
+
const n = data.length;
|
|
135
|
+
const result = new Array(n);
|
|
136
|
+
for (let i = 0; i < n; i++) {
|
|
137
|
+
const mapped = f(data[i]);
|
|
138
|
+
if (mapped.kind === "Error") return mapped;
|
|
139
|
+
result[i] = mapped.value;
|
|
140
|
+
}
|
|
141
|
+
return Result.ok(result);
|
|
142
|
+
};
|
|
143
|
+
Arr2.traverseTask = (f) => (data) => Task.from(() => Promise.all(data.map((a) => Deferred.toPromise(f(a)()))));
|
|
144
|
+
Arr2.sequence = (data) => (0, Arr2.traverse)((a) => a)(data);
|
|
145
|
+
Arr2.sequenceResult = (data) => (0, Arr2.traverseResult)((a) => a)(data);
|
|
146
|
+
Arr2.sequenceTask = (data) => (0, Arr2.traverseTask)((a) => a)(data);
|
|
147
|
+
Arr2.traverseTaskResult = (f) => (data) => Task.from(async () => {
|
|
148
|
+
const result = [];
|
|
149
|
+
for (const a of data) {
|
|
150
|
+
const r = await Deferred.toPromise(f(a)());
|
|
151
|
+
if (Result.isErr(r)) return r;
|
|
152
|
+
result.push(r.value);
|
|
153
|
+
}
|
|
154
|
+
return Result.ok(result);
|
|
155
|
+
});
|
|
156
|
+
Arr2.sequenceTaskResult = (data) => (0, Arr2.traverseTaskResult)((a) => a)(data);
|
|
157
|
+
Arr2.isNonEmpty = (data) => isNonEmptyList(data);
|
|
158
|
+
Arr2.size = (data) => data.length;
|
|
159
|
+
Arr2.some = (predicate) => (data) => {
|
|
160
|
+
const n = data.length;
|
|
161
|
+
for (let i = 0; i < n; i++) if (predicate(data[i])) return true;
|
|
162
|
+
return false;
|
|
163
|
+
};
|
|
164
|
+
Arr2.every = (predicate) => (data) => {
|
|
165
|
+
const n = data.length;
|
|
166
|
+
for (let i = 0; i < n; i++) if (!predicate(data[i])) return false;
|
|
167
|
+
return true;
|
|
168
|
+
};
|
|
169
|
+
Arr2.reverse = (data) => [...data].reverse();
|
|
170
|
+
Arr2.take = (n) => (data) => n <= 0 ? [] : data.slice(0, n);
|
|
171
|
+
Arr2.drop = (n) => (data) => data.slice(n);
|
|
172
|
+
Arr2.takeWhile = (predicate) => (data) => {
|
|
173
|
+
const result = [];
|
|
174
|
+
for (const a of data) {
|
|
175
|
+
if (!predicate(a)) break;
|
|
176
|
+
result.push(a);
|
|
177
|
+
}
|
|
178
|
+
return result;
|
|
179
|
+
};
|
|
180
|
+
Arr2.dropWhile = (predicate) => (data) => {
|
|
181
|
+
let i = 0;
|
|
182
|
+
while (i < data.length && predicate(data[i])) i++;
|
|
183
|
+
return data.slice(i);
|
|
184
|
+
};
|
|
185
|
+
Arr2.scan = (initial, f) => (data) => {
|
|
186
|
+
const n = data.length;
|
|
187
|
+
const result = new Array(n);
|
|
188
|
+
let acc = initial;
|
|
189
|
+
for (let i = 0; i < n; i++) {
|
|
190
|
+
acc = f(acc, data[i]);
|
|
191
|
+
result[i] = acc;
|
|
192
|
+
}
|
|
193
|
+
return result;
|
|
194
|
+
};
|
|
195
|
+
Arr2.splitAt = (index) => (data) => {
|
|
196
|
+
const i = Math.max(0, index);
|
|
197
|
+
return [data.slice(0, i), data.slice(i)];
|
|
198
|
+
};
|
|
199
|
+
})(Arr || (Arr = {}));
|
|
200
|
+
|
|
201
|
+
// src/Utils/Dict.ts
|
|
202
|
+
var Dict;
|
|
203
|
+
((Dict2) => {
|
|
204
|
+
Dict2.empty = () => new globalThis.Map();
|
|
205
|
+
Dict2.singleton = (key, value) => new globalThis.Map([[key, value]]);
|
|
206
|
+
Dict2.fromEntries = (entries2) => new globalThis.Map(entries2);
|
|
207
|
+
Dict2.fromRecord = (rec) => new globalThis.Map(Object.entries(rec));
|
|
208
|
+
Dict2.groupBy = (keyFn) => (items) => {
|
|
209
|
+
const result = new globalThis.Map();
|
|
210
|
+
for (const item of items) {
|
|
211
|
+
const key = keyFn(item);
|
|
212
|
+
const arr = result.get(key);
|
|
213
|
+
if (arr !== void 0) arr.push(item);
|
|
214
|
+
else result.set(key, [item]);
|
|
215
|
+
}
|
|
216
|
+
return result;
|
|
217
|
+
};
|
|
218
|
+
Dict2.has = (key) => (m) => m.has(key);
|
|
219
|
+
Dict2.lookup = (key) => (m) => m.has(key) ? Option.some(m.get(key)) : Option.none();
|
|
220
|
+
Dict2.size = (m) => m.size;
|
|
221
|
+
Dict2.isEmpty = (m) => m.size === 0;
|
|
222
|
+
Dict2.keys = (m) => [...m.keys()];
|
|
223
|
+
Dict2.values = (m) => [...m.values()];
|
|
224
|
+
Dict2.entries = (m) => [...m.entries()];
|
|
225
|
+
Dict2.insert = (key, value) => (m) => {
|
|
226
|
+
const result = new globalThis.Map(m);
|
|
227
|
+
result.set(key, value);
|
|
228
|
+
return result;
|
|
229
|
+
};
|
|
230
|
+
Dict2.remove = (key) => (m) => {
|
|
231
|
+
if (!m.has(key)) return m;
|
|
232
|
+
const result = new globalThis.Map(m);
|
|
233
|
+
result.delete(key);
|
|
234
|
+
return result;
|
|
235
|
+
};
|
|
236
|
+
Dict2.upsert = (key, f) => (m) => {
|
|
237
|
+
const result = new globalThis.Map(m);
|
|
238
|
+
result.set(key, f((0, Dict2.lookup)(key)(m)));
|
|
239
|
+
return result;
|
|
240
|
+
};
|
|
241
|
+
Dict2.map = (f) => (m) => {
|
|
242
|
+
const result = new globalThis.Map();
|
|
243
|
+
for (const [k, v] of m) {
|
|
244
|
+
result.set(k, f(v));
|
|
245
|
+
}
|
|
246
|
+
return result;
|
|
247
|
+
};
|
|
248
|
+
Dict2.mapWithKey = (f) => (m) => {
|
|
249
|
+
const result = new globalThis.Map();
|
|
250
|
+
for (const [k, v] of m) {
|
|
251
|
+
result.set(k, f(k, v));
|
|
252
|
+
}
|
|
253
|
+
return result;
|
|
254
|
+
};
|
|
255
|
+
Dict2.filter = (predicate) => (m) => {
|
|
256
|
+
const result = new globalThis.Map();
|
|
257
|
+
for (const [k, v] of m) {
|
|
258
|
+
if (predicate(v)) result.set(k, v);
|
|
259
|
+
}
|
|
260
|
+
return result;
|
|
261
|
+
};
|
|
262
|
+
Dict2.filterWithKey = (predicate) => (m) => {
|
|
263
|
+
const result = new globalThis.Map();
|
|
264
|
+
for (const [k, v] of m) {
|
|
265
|
+
if (predicate(k, v)) result.set(k, v);
|
|
266
|
+
}
|
|
267
|
+
return result;
|
|
268
|
+
};
|
|
269
|
+
Dict2.compact = (m) => {
|
|
270
|
+
const result = new globalThis.Map();
|
|
271
|
+
for (const [k, v] of m) {
|
|
272
|
+
if (v.kind === "Some") result.set(k, v.value);
|
|
273
|
+
}
|
|
274
|
+
return result;
|
|
275
|
+
};
|
|
276
|
+
Dict2.union = (other) => (m) => {
|
|
277
|
+
const result = new globalThis.Map(m);
|
|
278
|
+
for (const [k, v] of other) {
|
|
279
|
+
result.set(k, v);
|
|
280
|
+
}
|
|
281
|
+
return result;
|
|
282
|
+
};
|
|
283
|
+
Dict2.intersection = (other) => (m) => {
|
|
284
|
+
const result = new globalThis.Map();
|
|
285
|
+
for (const [k, v] of m) {
|
|
286
|
+
if (other.has(k)) result.set(k, v);
|
|
287
|
+
}
|
|
288
|
+
return result;
|
|
289
|
+
};
|
|
290
|
+
Dict2.difference = (other) => (m) => {
|
|
291
|
+
const result = new globalThis.Map();
|
|
292
|
+
for (const [k, v] of m) {
|
|
293
|
+
if (!other.has(k)) result.set(k, v);
|
|
294
|
+
}
|
|
295
|
+
return result;
|
|
296
|
+
};
|
|
297
|
+
Dict2.reduce = (init, f) => (m) => {
|
|
298
|
+
let acc = init;
|
|
299
|
+
for (const v of m.values()) {
|
|
300
|
+
acc = f(acc, v);
|
|
301
|
+
}
|
|
302
|
+
return acc;
|
|
303
|
+
};
|
|
304
|
+
Dict2.reduceWithKey = (init, f) => (m) => {
|
|
305
|
+
let acc = init;
|
|
306
|
+
for (const [k, v] of m) {
|
|
307
|
+
acc = f(acc, v, k);
|
|
308
|
+
}
|
|
309
|
+
return acc;
|
|
310
|
+
};
|
|
311
|
+
Dict2.toRecord = (m) => Object.fromEntries(m);
|
|
312
|
+
})(Dict || (Dict = {}));
|
|
313
|
+
|
|
314
|
+
// src/Utils/Num.ts
|
|
315
|
+
var Num;
|
|
316
|
+
((Num2) => {
|
|
317
|
+
Num2.range = (from, to, step = 1) => {
|
|
318
|
+
if (step <= 0 || from > to) return [];
|
|
319
|
+
const count = Math.floor((to - from) / step) + 1;
|
|
320
|
+
const result = new Array(count);
|
|
321
|
+
for (let i = 0; i < count; i++) {
|
|
322
|
+
result[i] = from + i * step;
|
|
323
|
+
}
|
|
324
|
+
return result;
|
|
325
|
+
};
|
|
326
|
+
Num2.clamp = (min, max) => (n) => Math.min(Math.max(n, min), max);
|
|
327
|
+
Num2.between = (min, max) => (n) => n >= min && n <= max;
|
|
328
|
+
Num2.parse = (s) => {
|
|
329
|
+
if (s.trim() === "") return Option.none();
|
|
330
|
+
const n = Number(s);
|
|
331
|
+
return isNaN(n) ? Option.none() : Option.some(n);
|
|
332
|
+
};
|
|
333
|
+
Num2.add = (b) => (a) => a + b;
|
|
334
|
+
Num2.subtract = (b) => (a) => a - b;
|
|
335
|
+
Num2.multiply = (b) => (a) => a * b;
|
|
336
|
+
Num2.divide = (b) => (a) => a / b;
|
|
337
|
+
})(Num || (Num = {}));
|
|
338
|
+
|
|
339
|
+
// src/Utils/Rec.ts
|
|
340
|
+
var Rec;
|
|
341
|
+
((Rec2) => {
|
|
342
|
+
Rec2.map = (f) => (data) => {
|
|
343
|
+
const keys2 = Object.keys(data);
|
|
344
|
+
const vals = Object.values(data);
|
|
345
|
+
const result = {};
|
|
346
|
+
for (let i = 0; i < keys2.length; i++) {
|
|
347
|
+
result[keys2[i]] = f(vals[i]);
|
|
348
|
+
}
|
|
349
|
+
return result;
|
|
350
|
+
};
|
|
351
|
+
Rec2.mapWithKey = (f) => (data) => {
|
|
352
|
+
const keys2 = Object.keys(data);
|
|
353
|
+
const vals = Object.values(data);
|
|
354
|
+
const result = {};
|
|
355
|
+
for (let i = 0; i < keys2.length; i++) {
|
|
356
|
+
result[keys2[i]] = f(keys2[i], vals[i]);
|
|
357
|
+
}
|
|
358
|
+
return result;
|
|
359
|
+
};
|
|
360
|
+
Rec2.filter = (predicate) => (data) => {
|
|
361
|
+
const result = {};
|
|
362
|
+
for (const [k, v] of Object.entries(data)) {
|
|
363
|
+
if (predicate(v)) result[k] = v;
|
|
364
|
+
}
|
|
365
|
+
return result;
|
|
366
|
+
};
|
|
367
|
+
Rec2.filterWithKey = (predicate) => (data) => {
|
|
368
|
+
const result = {};
|
|
369
|
+
for (const [k, v] of Object.entries(data)) {
|
|
370
|
+
if (predicate(k, v)) result[k] = v;
|
|
371
|
+
}
|
|
372
|
+
return result;
|
|
373
|
+
};
|
|
374
|
+
Rec2.lookup = (key) => (data) => Object.hasOwn(data, key) ? Option.some(data[key]) : Option.none();
|
|
375
|
+
Rec2.keys = (data) => Object.keys(data);
|
|
376
|
+
Rec2.values = (data) => Object.values(data);
|
|
377
|
+
Rec2.entries = (data) => Object.entries(data);
|
|
378
|
+
Rec2.fromEntries = (data) => Object.fromEntries(data);
|
|
379
|
+
Rec2.groupBy = (keyFn) => (items) => {
|
|
380
|
+
const result = {};
|
|
381
|
+
for (const item of items) {
|
|
382
|
+
const key = keyFn(item);
|
|
383
|
+
if (key in result) result[key].push(item);
|
|
384
|
+
else result[key] = [item];
|
|
385
|
+
}
|
|
386
|
+
return result;
|
|
387
|
+
};
|
|
388
|
+
Rec2.pick = (...pickedKeys) => (data) => {
|
|
389
|
+
const result = {};
|
|
390
|
+
for (const key of pickedKeys) {
|
|
391
|
+
if (Object.hasOwn(data, key)) {
|
|
392
|
+
result[key] = data[key];
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
return result;
|
|
396
|
+
};
|
|
397
|
+
Rec2.omit = (...omittedKeys) => (data) => {
|
|
398
|
+
const omitSet = new Set(omittedKeys);
|
|
399
|
+
const result = {};
|
|
400
|
+
for (const key of Object.keys(data)) {
|
|
401
|
+
if (!omitSet.has(key)) {
|
|
402
|
+
result[key] = data[key];
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
return result;
|
|
406
|
+
};
|
|
407
|
+
Rec2.merge = (other) => (data) => ({
|
|
408
|
+
...data,
|
|
409
|
+
...other
|
|
410
|
+
});
|
|
411
|
+
Rec2.isEmpty = (data) => Object.keys(data).length === 0;
|
|
412
|
+
Rec2.size = (data) => Object.keys(data).length;
|
|
413
|
+
Rec2.mapKeys = (f) => (data) => {
|
|
414
|
+
const result = {};
|
|
415
|
+
for (const [k, v] of Object.entries(data)) {
|
|
416
|
+
result[f(k)] = v;
|
|
417
|
+
}
|
|
418
|
+
return result;
|
|
419
|
+
};
|
|
420
|
+
Rec2.compact = (data) => {
|
|
421
|
+
const result = {};
|
|
422
|
+
for (const [k, v] of Object.entries(data)) {
|
|
423
|
+
if (v.kind === "Some") result[k] = v.value;
|
|
424
|
+
}
|
|
425
|
+
return result;
|
|
426
|
+
};
|
|
427
|
+
})(Rec || (Rec = {}));
|
|
428
|
+
|
|
429
|
+
// src/Utils/Str.ts
|
|
430
|
+
var Str;
|
|
431
|
+
((Str2) => {
|
|
432
|
+
Str2.split = (separator) => (s) => s.split(separator);
|
|
433
|
+
Str2.trim = (s) => s.trim();
|
|
434
|
+
Str2.includes = (substring) => (s) => s.includes(substring);
|
|
435
|
+
Str2.startsWith = (prefix) => (s) => s.startsWith(prefix);
|
|
436
|
+
Str2.endsWith = (suffix) => (s) => s.endsWith(suffix);
|
|
437
|
+
Str2.toUpperCase = (s) => s.toUpperCase();
|
|
438
|
+
Str2.toLowerCase = (s) => s.toLowerCase();
|
|
439
|
+
Str2.lines = (s) => s.split(/\r?\n|\r/);
|
|
440
|
+
Str2.words = (s) => s.trim().split(/\s+/).filter(Boolean);
|
|
441
|
+
Str2.parse = {
|
|
442
|
+
/**
|
|
443
|
+
* Parses a string as an integer (base 10). Returns `None` if the result is `NaN`.
|
|
444
|
+
*
|
|
445
|
+
* @example
|
|
446
|
+
* ```ts
|
|
447
|
+
* Str.parse.int("42"); // Some(42)
|
|
448
|
+
* Str.parse.int("3.7"); // Some(3)
|
|
449
|
+
* Str.parse.int("abc"); // None
|
|
450
|
+
* ```
|
|
451
|
+
*/
|
|
452
|
+
int: (s) => {
|
|
453
|
+
const n = parseInt(s, 10);
|
|
454
|
+
return isNaN(n) ? Option.none() : Option.some(n);
|
|
455
|
+
},
|
|
456
|
+
/**
|
|
457
|
+
* Parses a string as a floating-point number. Returns `None` if the result is `NaN`.
|
|
458
|
+
*
|
|
459
|
+
* @example
|
|
460
|
+
* ```ts
|
|
461
|
+
* Str.parse.float("3.14"); // Some(3.14)
|
|
462
|
+
* Str.parse.float("42"); // Some(42)
|
|
463
|
+
* Str.parse.float("abc"); // None
|
|
464
|
+
* ```
|
|
465
|
+
*/
|
|
466
|
+
float: (s) => {
|
|
467
|
+
const n = parseFloat(s);
|
|
468
|
+
return isNaN(n) ? Option.none() : Option.some(n);
|
|
469
|
+
}
|
|
470
|
+
};
|
|
471
|
+
})(Str || (Str = {}));
|
|
472
|
+
|
|
473
|
+
// src/Utils/Uniq.ts
|
|
474
|
+
var Uniq;
|
|
475
|
+
((Uniq2) => {
|
|
476
|
+
Uniq2.empty = () => new globalThis.Set();
|
|
477
|
+
Uniq2.singleton = (item) => new globalThis.Set([item]);
|
|
478
|
+
Uniq2.fromArray = (arr) => new globalThis.Set(arr);
|
|
479
|
+
Uniq2.has = (item) => (s) => s.has(item);
|
|
480
|
+
Uniq2.size = (s) => s.size;
|
|
481
|
+
Uniq2.isEmpty = (s) => s.size === 0;
|
|
482
|
+
Uniq2.isSubsetOf = (other) => (s) => {
|
|
483
|
+
const set = s;
|
|
484
|
+
if (typeof set.isSubsetOf === "function") return set.isSubsetOf(other);
|
|
485
|
+
for (const item of s) {
|
|
486
|
+
if (!other.has(item)) return false;
|
|
487
|
+
}
|
|
488
|
+
return true;
|
|
489
|
+
};
|
|
490
|
+
Uniq2.insert = (item) => (s) => {
|
|
491
|
+
if (s.has(item)) return s;
|
|
492
|
+
const result = new globalThis.Set(s);
|
|
493
|
+
result.add(item);
|
|
494
|
+
return result;
|
|
495
|
+
};
|
|
496
|
+
Uniq2.remove = (item) => (s) => {
|
|
497
|
+
if (!s.has(item)) return s;
|
|
498
|
+
const result = new globalThis.Set(s);
|
|
499
|
+
result.delete(item);
|
|
500
|
+
return result;
|
|
501
|
+
};
|
|
502
|
+
Uniq2.map = (f) => (s) => {
|
|
503
|
+
const result = new globalThis.Set();
|
|
504
|
+
for (const item of s) {
|
|
505
|
+
result.add(f(item));
|
|
506
|
+
}
|
|
507
|
+
return result;
|
|
508
|
+
};
|
|
509
|
+
Uniq2.filter = (predicate) => (s) => {
|
|
510
|
+
const result = new globalThis.Set();
|
|
511
|
+
for (const item of s) {
|
|
512
|
+
if (predicate(item)) result.add(item);
|
|
513
|
+
}
|
|
514
|
+
return result;
|
|
515
|
+
};
|
|
516
|
+
Uniq2.union = (other) => (s) => {
|
|
517
|
+
const set = s;
|
|
518
|
+
if (typeof set.union === "function") return set.union(other);
|
|
519
|
+
const result = new globalThis.Set(s);
|
|
520
|
+
for (const item of other) result.add(item);
|
|
521
|
+
return result;
|
|
522
|
+
};
|
|
523
|
+
Uniq2.intersection = (other) => (s) => {
|
|
524
|
+
const set = s;
|
|
525
|
+
if (typeof set.intersection === "function") return set.intersection(other);
|
|
526
|
+
const result = new globalThis.Set();
|
|
527
|
+
for (const item of s) if (other.has(item)) result.add(item);
|
|
528
|
+
return result;
|
|
529
|
+
};
|
|
530
|
+
Uniq2.difference = (other) => (s) => {
|
|
531
|
+
const set = s;
|
|
532
|
+
if (typeof set.difference === "function") return set.difference(other);
|
|
533
|
+
const result = new globalThis.Set();
|
|
534
|
+
for (const item of s) if (!other.has(item)) result.add(item);
|
|
535
|
+
return result;
|
|
536
|
+
};
|
|
537
|
+
Uniq2.reduce = (init, f) => (s) => {
|
|
538
|
+
let acc = init;
|
|
539
|
+
for (const item of s) {
|
|
540
|
+
acc = f(acc, item);
|
|
541
|
+
}
|
|
542
|
+
return acc;
|
|
543
|
+
};
|
|
544
|
+
Uniq2.toArray = (s) => [...s];
|
|
545
|
+
})(Uniq || (Uniq = {}));
|
|
546
|
+
|
|
547
|
+
export {
|
|
548
|
+
Arr,
|
|
549
|
+
Dict,
|
|
550
|
+
Num,
|
|
551
|
+
Rec,
|
|
552
|
+
Str,
|
|
553
|
+
Uniq
|
|
554
|
+
};
|