functionalscript 0.0.390 → 0.0.393
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/com/cpp/module.f.cjs +41 -31
- package/com/cs/module.f.cjs +60 -41
- package/com/types/module.f.cjs +6 -2
- package/commonjs/build/module.f.cjs +19 -14
- package/commonjs/package/dependencies/module.f.cjs +5 -2
- package/commonjs/package/module.f.cjs +4 -2
- package/commonjs/path/module.f.cjs +16 -14
- package/dev/test/module.f.cjs +19 -0
- package/doc/vm.md +45 -4
- package/html/module.f.cjs +14 -9
- package/json/module.f.cjs +18 -11
- package/json/tokenizer/module.f.cjs +128 -164
- package/nodejs/version/module.f.cjs +4 -4
- package/package.json +1 -1
- package/sha2/module.f.cjs +29 -29
- package/test.f.cjs +3 -1
- package/text/encoding/module.f.cjs +0 -2
- package/text/module.f.cjs +2 -1
- package/types/array/module.f.cjs +2 -1
- package/types/bigint/module.f.cjs +10 -0
- package/types/bigint/test.f.cjs +8 -0
- package/types/btree/find/module.f.cjs +3 -2
- package/types/btree/remove/module.f.cjs +6 -5
- package/types/btree/set/module.f.cjs +9 -5
- package/types/function/operator/module.f.cjs +11 -11
- package/types/list/module.f.cjs +32 -21
- package/types/list/test.f.cjs +0 -20
- package/types/map/module.f.cjs +11 -10
- package/types/module.f.cjs +1 -1
- package/types/number/module.f.cjs +17 -0
- package/types/number/test.f.cjs +23 -0
- package/types/object/module.f.cjs +9 -6
- package/types/object/test.html +9 -0
- package/types/result/module.cjs +3 -2
- package/types/{stringset → string_set}/module.f.cjs +12 -8
- /package/types/{stringset → string_set}/test.f.cjs +0 -0
package/test.f.cjs
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
const i = require('./module.f.cjs')
|
|
2
2
|
|
|
3
3
|
require('./types/list/test.f.cjs')
|
|
4
|
+
require('./types/number/test.f.cjs')
|
|
5
|
+
require('./types/bigint/module.f.cjs')
|
|
4
6
|
require('./types/array/test.f.cjs')
|
|
5
7
|
require('./types/btree/test.f.cjs')
|
|
6
8
|
require('./sha2/test.f.cjs')
|
|
@@ -12,7 +14,7 @@ require('./commonjs/package/dependencies/test.f.cjs')
|
|
|
12
14
|
require('./commonjs/package/test.f.cjs')
|
|
13
15
|
require('./commonjs/path/test.f.cjs')
|
|
14
16
|
require('./types/function/compare/test.f.cjs')
|
|
15
|
-
require('./types/
|
|
17
|
+
require('./types/string_set/test.f.cjs')
|
|
16
18
|
require('./types/option/test.f.cjs')
|
|
17
19
|
require('./commonjs/build/test.f.cjs')
|
|
18
20
|
require('./types/range/test.f.cjs')
|
|
@@ -55,10 +55,8 @@ const codePointToUtf16 = input =>
|
|
|
55
55
|
return [input & 0xffff]
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
-
/** @type {(input: list.List<number>) => list.List<ByteResult>} */
|
|
59
58
|
const codePointListToUtf8List = flatMap(codePointToUtf8)
|
|
60
59
|
|
|
61
|
-
/** @type {(input: list.List<i32>) => list.List<u16>} */
|
|
62
60
|
const codePointListToUtf16List = flatMap(codePointToUtf16)
|
|
63
61
|
|
|
64
62
|
/** @type {operator.StateScan<number, Utf8State, list.List<CodePointResult>>} */
|
package/text/module.f.cjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
const list = require('../types/list/module.f.cjs')
|
|
2
|
+
const { flatMap } = list
|
|
2
3
|
|
|
3
4
|
/** @typedef {ItemThunk|ItemArray} Block */
|
|
4
5
|
|
|
@@ -15,7 +16,7 @@ const flat = indent => {
|
|
|
15
16
|
const f = prefix => {
|
|
16
17
|
/** @type {(item: Item) => list.List<string>} */
|
|
17
18
|
const g = item => typeof (item) === 'string' ? [`${prefix}${item}`] : f(`${prefix}${indent}`)(item)
|
|
18
|
-
return
|
|
19
|
+
return flatMap(g)
|
|
19
20
|
}
|
|
20
21
|
|
|
21
22
|
return f('')
|
package/types/array/module.f.cjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
const option = require('../option/module.f.cjs')
|
|
2
|
+
const { map } = option
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* @template T
|
|
@@ -97,7 +98,7 @@ const splitFirst = a => {
|
|
|
97
98
|
/** @typedef {typeof a[0]} T*/
|
|
98
99
|
/** @type {(_: T) => readonly[T, readonly T[]]} */
|
|
99
100
|
const split = first => [first, uncheckTail(a)]
|
|
100
|
-
return
|
|
101
|
+
return map(split)(a[0])
|
|
101
102
|
}
|
|
102
103
|
|
|
103
104
|
/** @type {<T>(_: readonly T[]) => readonly T[]|undefined} */
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
const _ = require('../types/module.f.cjs')
|
|
2
2
|
const list = require('../../list/module.f.cjs')
|
|
3
3
|
const cmp = require('../../function/compare/module.f.cjs')
|
|
4
|
+
const { index3, index5 } = cmp
|
|
4
5
|
const array = require('../../array/module.f.cjs')
|
|
5
6
|
|
|
6
7
|
/**
|
|
@@ -62,8 +63,8 @@ const child = item =>
|
|
|
62
63
|
|
|
63
64
|
/** @type {<T>(c: cmp.Compare<T>) => (node: _.Node<T>) => Result<T>} */
|
|
64
65
|
const find = c => {
|
|
65
|
-
const i3 =
|
|
66
|
-
const i5 =
|
|
66
|
+
const i3 = index3(c)
|
|
67
|
+
const i5 = index5(c)
|
|
67
68
|
/** @typedef {typeof c extends cmp.Compare<infer T> ? T : never} T */
|
|
68
69
|
/** @type {(prior: Path<T>) => (node: _.Node<T>) => Result<T>} */
|
|
69
70
|
const f = tail => node => {
|
|
@@ -2,8 +2,9 @@ const _ = require('../types/module.f.cjs')
|
|
|
2
2
|
const cmp = require('../../function/compare/module.f.cjs')
|
|
3
3
|
const find = require('../find/module.f.cjs')
|
|
4
4
|
const list = require('../../list/module.f.cjs')
|
|
5
|
+
const { reduce: listReduce, concat, next } = list
|
|
5
6
|
const array = require('../../array/module.f.cjs')
|
|
6
|
-
const
|
|
7
|
+
const { map } = require('../../option/module.f.cjs')
|
|
7
8
|
|
|
8
9
|
/**
|
|
9
10
|
* @template T
|
|
@@ -110,7 +111,7 @@ const reduceX = ms => ([i, n]) => a => {
|
|
|
110
111
|
}
|
|
111
112
|
}
|
|
112
113
|
|
|
113
|
-
const reduce =
|
|
114
|
+
const reduce = listReduce(reduceX([reduceValue0, reduceValue2]))
|
|
114
115
|
|
|
115
116
|
const initReduce = reduceX([initValue0, initValue1])
|
|
116
117
|
|
|
@@ -123,7 +124,7 @@ const nodeRemove = c => node => {
|
|
|
123
124
|
/** @type {(n: _.Node<T>) => (f: (v: T) => find.PathItem<T>) => RemovePath<T>} */
|
|
124
125
|
const branch = n => f => {
|
|
125
126
|
const [v, p] = path(/** @type {find.Path<T>} */(undefined))(n)
|
|
126
|
-
return { first: p.first, tail:
|
|
127
|
+
return { first: p.first, tail: concat(p.tail)({ first: f(v), tail }) }
|
|
127
128
|
}
|
|
128
129
|
const [i, n] = first
|
|
129
130
|
switch (i) {
|
|
@@ -147,7 +148,7 @@ const nodeRemove = c => node => {
|
|
|
147
148
|
const r = f()
|
|
148
149
|
if (r === undefined) { return node }
|
|
149
150
|
const { first, tail } = r
|
|
150
|
-
const tailR =
|
|
151
|
+
const tailR = next(tail)
|
|
151
152
|
if (tailR === undefined) { return first }
|
|
152
153
|
const { first: tf, tail: tt } = tailR
|
|
153
154
|
const result = reduce(initReduce(tf)(first))(tt)
|
|
@@ -155,7 +156,7 @@ const nodeRemove = c => node => {
|
|
|
155
156
|
}
|
|
156
157
|
|
|
157
158
|
/** @type {<T>(c: cmp.Compare<T>) => (tree: _.Tree<T>) => _.Tree<T>} */
|
|
158
|
-
const remove =
|
|
159
|
+
const remove = c => map(nodeRemove(c))
|
|
159
160
|
|
|
160
161
|
module.exports = {
|
|
161
162
|
/** @readonly */
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
const _ = require('../types/module.f.cjs')
|
|
2
|
-
const
|
|
2
|
+
const btreeFind = require('../find/module.f.cjs')
|
|
3
|
+
const { find } = btreeFind
|
|
3
4
|
const cmp = require('../../function/compare/module.f.cjs')
|
|
4
5
|
const list = require('../../list/module.f.cjs')
|
|
6
|
+
const { reduce } = list
|
|
5
7
|
|
|
6
8
|
/**
|
|
7
9
|
* @template T
|
|
@@ -11,8 +13,8 @@ const list = require('../../list/module.f.cjs')
|
|
|
11
13
|
/** @type {<T>(b: _.Branch5<T> | _.Branch7<T>) => Branch1To3<T>} */
|
|
12
14
|
const b57 = b => b.length === 5 ? [b] : [[b[0], b[1], b[2]], b[3], [b[4], b[5], b[6]]]
|
|
13
15
|
|
|
14
|
-
/** @type {<T>(i:
|
|
15
|
-
const
|
|
16
|
+
/** @type {<T>(i: btreeFind.PathItem<T>) => (a: Branch1To3<T>) => Branch1To3<T>} */
|
|
17
|
+
const reduceOp = ([i, x]) => a => {
|
|
16
18
|
switch (i) {
|
|
17
19
|
case 0: {
|
|
18
20
|
switch (x.length) {
|
|
@@ -32,9 +34,11 @@ const reduce = ([i, x]) => a => {
|
|
|
32
34
|
}
|
|
33
35
|
}
|
|
34
36
|
|
|
37
|
+
const reduceBranch = reduce(reduceOp)
|
|
38
|
+
|
|
35
39
|
/** @type {<T>(c: cmp.Compare<T>) => (value: T) => (node: _.Node<T>) => _.Node<T>} */
|
|
36
40
|
const nodeSet = c => value => node => {
|
|
37
|
-
const { first, tail } = find
|
|
41
|
+
const { first, tail } = find(c)(node)
|
|
38
42
|
const [i, x] = first;
|
|
39
43
|
/** @typedef {typeof value} T */
|
|
40
44
|
/** @type {() => Branch1To3<T>} */
|
|
@@ -77,7 +81,7 @@ const nodeSet = c => value => node => {
|
|
|
77
81
|
}
|
|
78
82
|
}
|
|
79
83
|
}
|
|
80
|
-
const r =
|
|
84
|
+
const r = reduceBranch(f())(tail)
|
|
81
85
|
return r.length === 1 ? r[0] : r
|
|
82
86
|
}
|
|
83
87
|
|
|
@@ -16,11 +16,6 @@ const join = separator => value => prior => `${prior}${separator}${value}`
|
|
|
16
16
|
/** @type {Fold<string>} */
|
|
17
17
|
const concat = i => acc => `${acc}${i}`
|
|
18
18
|
|
|
19
|
-
/** @type {Fold<number>} */
|
|
20
|
-
const addition = a => b => a + b
|
|
21
|
-
|
|
22
|
-
const increment = addition(1)
|
|
23
|
-
|
|
24
19
|
/**
|
|
25
20
|
* @template T
|
|
26
21
|
* @template R
|
|
@@ -38,12 +33,6 @@ const logicalNot = v => !v
|
|
|
38
33
|
/** @type {<T>(a: T) => (b: T) => boolean} */
|
|
39
34
|
const strictEqual = a => b => a === b
|
|
40
35
|
|
|
41
|
-
/** @type {Fold<number>} */
|
|
42
|
-
const min = a => b => a < b ? a : b
|
|
43
|
-
|
|
44
|
-
/** @type {Fold<number>} */
|
|
45
|
-
const max = a => b => a > b ? a : b
|
|
46
|
-
|
|
47
36
|
/**
|
|
48
37
|
* @template I,O
|
|
49
38
|
* @typedef {(input: I) => readonly[O, Scan<I,O>]} Scan
|
|
@@ -74,6 +63,17 @@ const reduceToScan = reduce => prior => i => {
|
|
|
74
63
|
/** @type {<T>(fold: Fold<T>) => Scan<T, T>} */
|
|
75
64
|
const foldToScan = op => init => [init, reduceToScan(op)(init)]
|
|
76
65
|
|
|
66
|
+
/** @type {Fold<number>} */
|
|
67
|
+
const addition = a => b => a + b
|
|
68
|
+
|
|
69
|
+
/** @type {Fold<number>} */
|
|
70
|
+
const min = a => b => a < b ? a : b
|
|
71
|
+
|
|
72
|
+
/** @type {Fold<number>} */
|
|
73
|
+
const max = a => b => a > b ? a : b
|
|
74
|
+
|
|
75
|
+
const increment = addition(1)
|
|
76
|
+
|
|
77
77
|
const counter = () => increment
|
|
78
78
|
|
|
79
79
|
module.exports = {
|
package/types/list/module.f.cjs
CHANGED
|
@@ -1,6 +1,15 @@
|
|
|
1
1
|
const { compose, identity } = require('../function/module.f.cjs')
|
|
2
2
|
const operator = require('../function/operator/module.f.cjs')
|
|
3
|
-
const {
|
|
3
|
+
const {
|
|
4
|
+
join: joinOp,
|
|
5
|
+
concat: concatOp,
|
|
6
|
+
counter,
|
|
7
|
+
logicalNot,
|
|
8
|
+
strictEqual,
|
|
9
|
+
stateScanToScan,
|
|
10
|
+
reduceToScan,
|
|
11
|
+
foldToScan
|
|
12
|
+
} = operator
|
|
4
13
|
|
|
5
14
|
/**
|
|
6
15
|
* @template T
|
|
@@ -99,10 +108,12 @@ const iterable = list => ({
|
|
|
99
108
|
}
|
|
100
109
|
})
|
|
101
110
|
|
|
111
|
+
const { from } = Array
|
|
112
|
+
|
|
102
113
|
/** @type {<T>(list: List<T>) => readonly T[]} */
|
|
103
114
|
const toArray = list => {
|
|
104
115
|
const u = trampoline(list)
|
|
105
|
-
return u instanceof Array ? u :
|
|
116
|
+
return u instanceof Array ? u : from(iterable(u))
|
|
106
117
|
}
|
|
107
118
|
|
|
108
119
|
/** @type {<I, O>(step: (n: NonEmpty<I>) => List<O>) => (input: List<I>) => Thunk<O>} */
|
|
@@ -192,17 +203,23 @@ const last = first => tail => {
|
|
|
192
203
|
/** @type {<D>(def: D) => <T>(f: (value: T) => boolean) => (input: List<T>) => D|T} */
|
|
193
204
|
const find = def => f => input => first(def)(filter(f)(input))
|
|
194
205
|
|
|
206
|
+
const findTrue = find(false)
|
|
207
|
+
|
|
195
208
|
/** @type {(input: List<boolean>) => boolean} */
|
|
196
|
-
const some = input =>
|
|
197
|
-
(false)
|
|
209
|
+
const some = input => findTrue
|
|
198
210
|
(/** @type {(_: boolean) => boolean} */(identity))
|
|
199
211
|
(input)
|
|
200
212
|
|
|
213
|
+
/** @type {<T>(f: List<T>) => Thunk<boolean>} */
|
|
214
|
+
const mapTrue = map(() => true)
|
|
215
|
+
|
|
201
216
|
/** @type {<T>(input: List<T>) => boolean} */
|
|
202
|
-
const isEmpty = input => !some(
|
|
217
|
+
const isEmpty = input => !some(mapTrue(input))
|
|
218
|
+
|
|
219
|
+
const mapNot = map(logicalNot)
|
|
203
220
|
|
|
204
221
|
/** @type {(input: List<boolean>) => boolean} */
|
|
205
|
-
const every = input => !some(
|
|
222
|
+
const every = input => !some(mapNot(input))
|
|
206
223
|
|
|
207
224
|
/** @type {<T>(value: T) => (sequence: List<T>) => boolean} */
|
|
208
225
|
const includes = value => input => some(map(strictEqual(value))(input))
|
|
@@ -244,17 +261,13 @@ const reduce = op => init => input => last(init)(reduceScan(op)(init)(input))
|
|
|
244
261
|
/** @type {<T>(op: operator.Fold<T>) => <D>(def: D) => (input: List<T>) => D|T} */
|
|
245
262
|
const fold = op => def => input => last(def)(scan(foldToScan(op))(input))
|
|
246
263
|
|
|
247
|
-
const sum = fold(operator.addition)(0)
|
|
248
|
-
|
|
249
|
-
const min = fold(operator.min)(undefined)
|
|
250
|
-
|
|
251
|
-
const max = fold(operator.max)(undefined)
|
|
252
|
-
|
|
253
264
|
/** @type {(separator: string) => (input: List<string>) => string} */
|
|
254
|
-
const join = separator => fold(
|
|
265
|
+
const join = separator => fold(joinOp(separator))('')
|
|
266
|
+
|
|
267
|
+
const stringConcat = fold(concatOp)('')
|
|
255
268
|
|
|
256
269
|
/** @type {<T>(input: List<T>) => number} */
|
|
257
|
-
const length = reduce(
|
|
270
|
+
const length = reduce(counter)(0)
|
|
258
271
|
|
|
259
272
|
/**
|
|
260
273
|
* @template T
|
|
@@ -267,7 +280,9 @@ const entryOperator = index => value => [[index, value], index + 1]
|
|
|
267
280
|
/** @type {<T>(input: List<T>) => Thunk<Entry<T>>} */
|
|
268
281
|
const entries = input => {
|
|
269
282
|
/** @typedef {typeof input extends List<infer T> ? T : never} T */
|
|
270
|
-
|
|
283
|
+
/** @type {operator.StateScan<T, Number, Entry<T>>} */
|
|
284
|
+
const o = entryOperator
|
|
285
|
+
return stateScan(o)(0)(input)
|
|
271
286
|
}
|
|
272
287
|
|
|
273
288
|
/** @type {<T>(value: T) => (prior: List<T>) => List<T>} */
|
|
@@ -356,14 +371,10 @@ module.exports = {
|
|
|
356
371
|
/** @readonly */
|
|
357
372
|
fold,
|
|
358
373
|
/** @readonly */
|
|
359
|
-
sum,
|
|
360
|
-
/** @readonly */
|
|
361
|
-
min,
|
|
362
|
-
/** @readonly */
|
|
363
|
-
max,
|
|
364
|
-
/** @readonly */
|
|
365
374
|
join,
|
|
366
375
|
/** @readonly */
|
|
376
|
+
stringConcat,
|
|
377
|
+
/** @readonly */
|
|
367
378
|
length,
|
|
368
379
|
/** @readonly */
|
|
369
380
|
entries,
|
package/types/list/test.f.cjs
CHANGED
|
@@ -99,11 +99,6 @@ const stringify = sequence => json.stringify(sort)(_.toArray(sequence))
|
|
|
99
99
|
if (result !== '[2,5,9,14]') { throw result }
|
|
100
100
|
}
|
|
101
101
|
|
|
102
|
-
{
|
|
103
|
-
const result = _.sum([2, 3, 4, 5])
|
|
104
|
-
if (result !== 14) { throw result }
|
|
105
|
-
}
|
|
106
|
-
|
|
107
102
|
{
|
|
108
103
|
const result = _.fold(addition)(undefined)([2, 3, 4, 5])
|
|
109
104
|
if (result !== 14) { throw result }
|
|
@@ -211,21 +206,6 @@ const map5 = _.map(x => x > 5)
|
|
|
211
206
|
if (!result) { throw result }
|
|
212
207
|
}
|
|
213
208
|
|
|
214
|
-
{
|
|
215
|
-
const result = _.min([])
|
|
216
|
-
if (result !== undefined) { throw result }
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
{
|
|
220
|
-
const result = _.min([1, 2, 12, -4, 8])
|
|
221
|
-
if (result !== -4) { throw result }
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
{
|
|
225
|
-
const result = _.max([1, 2, 12, -4, 8])
|
|
226
|
-
if (result !== 12) { throw result }
|
|
227
|
-
}
|
|
228
|
-
|
|
229
209
|
{
|
|
230
210
|
const result = _.isEmpty(() => [])
|
|
231
211
|
if (result !== true) { throw result }
|
package/types/map/module.f.cjs
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
const
|
|
2
|
-
const btree = require('../btree/module.f.cjs')
|
|
1
|
+
const btreeTypes = require('../btree/types/module.f.cjs')
|
|
3
2
|
const { values } = require("../btree/module.f.cjs")
|
|
4
|
-
const
|
|
5
|
-
const
|
|
3
|
+
const btreeFind = require('../btree/find/module.f.cjs')
|
|
4
|
+
const { value, find } = btreeFind
|
|
5
|
+
const btreeSet = require('../btree/set/module.f.cjs').set
|
|
6
6
|
const compare = require('../function/compare/module.f.cjs')
|
|
7
7
|
const { stringCmp } = require('../function/compare/module.f.cjs')
|
|
8
8
|
const list = require('../list/module.f.cjs')
|
|
9
|
-
const
|
|
9
|
+
const { reduce } = list
|
|
10
|
+
const { remove: btreeRemove } = require('../btree/remove/module.f.cjs')
|
|
10
11
|
|
|
11
12
|
/** @typedef {compare.Sign} Sign */
|
|
12
13
|
|
|
@@ -22,7 +23,7 @@ const btRemove = require('../btree/remove/module.f.cjs')
|
|
|
22
23
|
|
|
23
24
|
/**
|
|
24
25
|
* @template T
|
|
25
|
-
* @typedef {
|
|
26
|
+
* @typedef {btreeTypes.Tree<Entry<T>>} Map
|
|
26
27
|
*/
|
|
27
28
|
|
|
28
29
|
/** @type {(a: string) => <T>(b: Entry<T>) => Sign} */
|
|
@@ -31,12 +32,12 @@ const keyCmp = a => ([b]) => stringCmp(a)(b)
|
|
|
31
32
|
/** @type {(name: string) => <T>(map: Map<T>) => T|undefined} */
|
|
32
33
|
const at = name => map => {
|
|
33
34
|
if (map === undefined) { return undefined }
|
|
34
|
-
const result =
|
|
35
|
+
const result = value(find(keyCmp(name))(map).first)
|
|
35
36
|
return result === undefined ? undefined : result[1]
|
|
36
37
|
}
|
|
37
38
|
|
|
38
39
|
/** @type {<T>(entry: Entry<T>) => (map: Map<T>) => Map<T>} */
|
|
39
|
-
const setEntry = entry =>
|
|
40
|
+
const setEntry = entry => btreeSet(keyCmp(entry[0]))(entry)
|
|
40
41
|
|
|
41
42
|
/** @type {(name: string) => <T>(value: T) => (map: Map<T>) => Map<T>} */
|
|
42
43
|
const set = name => value => setEntry([name, value])
|
|
@@ -45,10 +46,10 @@ const set = name => value => setEntry([name, value])
|
|
|
45
46
|
const entries = values
|
|
46
47
|
|
|
47
48
|
/** @type {<T>(entries: list.List<Entry<T>>) => Map<T>} */
|
|
48
|
-
const fromEntries =
|
|
49
|
+
const fromEntries = reduce(setEntry)(undefined)
|
|
49
50
|
|
|
50
51
|
/** @type {(name: string) => <T>(map: Map<T>) => Map<T>} */
|
|
51
|
-
const remove =
|
|
52
|
+
const remove = name => btreeRemove(keyCmp(name))
|
|
52
53
|
|
|
53
54
|
module.exports = {
|
|
54
55
|
/** @readonly */
|
package/types/module.f.cjs
CHANGED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
const { fold } = require('../list/module.f.cjs')
|
|
2
|
+
const { addition, min: minOp, max: maxOp } = require('../function/operator/module.f.cjs')
|
|
3
|
+
|
|
4
|
+
const sum = fold(addition)(0)
|
|
5
|
+
|
|
6
|
+
const min = fold(minOp)(undefined)
|
|
7
|
+
|
|
8
|
+
const max = fold(maxOp)(undefined)
|
|
9
|
+
|
|
10
|
+
module.exports = {
|
|
11
|
+
/** @readonly */
|
|
12
|
+
sum,
|
|
13
|
+
/** @readonly */
|
|
14
|
+
min,
|
|
15
|
+
/** @readonly */
|
|
16
|
+
max,
|
|
17
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
const { sum, min, max } = require('./module.f.cjs')
|
|
2
|
+
|
|
3
|
+
{
|
|
4
|
+
const result = sum([2, 3, 4, 5])
|
|
5
|
+
if (result !== 14) { throw result }
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
{
|
|
9
|
+
const result = min([])
|
|
10
|
+
if (result !== undefined) { throw result }
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
{
|
|
14
|
+
const result = min([1, 2, 12, -4, 8])
|
|
15
|
+
if (result !== -4) { throw result }
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
{
|
|
19
|
+
const result = max([1, 2, 12, -4, 8])
|
|
20
|
+
if (result !== 12) { throw result }
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
module.exports = {}
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
const list = require('../list/module.f.cjs')
|
|
2
|
+
const { iterable } = list
|
|
2
3
|
const map = require('../map/module.f.cjs')
|
|
4
|
+
const { entries: mapEntries, fromEntries: mapFromEntries } = map
|
|
5
|
+
const { getOwnPropertyDescriptor, fromEntries: objectFromEntries } = Object
|
|
3
6
|
|
|
4
7
|
/**
|
|
5
8
|
* @template T
|
|
@@ -14,16 +17,16 @@ const map = require('../map/module.f.cjs')
|
|
|
14
17
|
*/
|
|
15
18
|
|
|
16
19
|
/** @type {(name: string) => <T>(object: Map<T>) => T|undefined} */
|
|
17
|
-
const at = name => object =>
|
|
20
|
+
const at = name => object => getOwnPropertyDescriptor(object, name)?.value
|
|
18
21
|
|
|
19
|
-
/** @type {<T>(
|
|
20
|
-
const sort =
|
|
22
|
+
/** @type {<T>(e: list.List<Entry<T>>) => list.List<Entry<T>>} */
|
|
23
|
+
const sort = e => mapEntries(mapFromEntries(e))
|
|
21
24
|
|
|
22
|
-
/** @type {<T>(
|
|
23
|
-
const fromEntries =
|
|
25
|
+
/** @type {<T>(e: list.List<Entry<T>>) => Map<T>} */
|
|
26
|
+
const fromEntries = e => objectFromEntries(iterable(e))
|
|
24
27
|
|
|
25
28
|
/** @type {<T>(m: map.Map<T>) => Map<T>} */
|
|
26
|
-
const fromMap =
|
|
29
|
+
const fromMap = m => fromEntries(mapEntries(m))
|
|
27
30
|
|
|
28
31
|
module.exports = {
|
|
29
32
|
/** @readonly */
|
package/types/result/module.cjs
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
const result = require('./module.f.cjs')
|
|
2
|
+
const { ok, error } = result
|
|
2
3
|
|
|
3
4
|
/** @type {<T>(f: () => T) => result.Result<T, unknown>} */
|
|
4
5
|
const tryCatch = f => {
|
|
5
6
|
// Side effect: `try catch` is not allowed in FunctionalScript.
|
|
6
7
|
try {
|
|
7
|
-
return
|
|
8
|
+
return ok(f())
|
|
8
9
|
} catch (e) {
|
|
9
|
-
return
|
|
10
|
+
return error(e)
|
|
10
11
|
}
|
|
11
12
|
}
|
|
12
13
|
|
|
@@ -1,25 +1,29 @@
|
|
|
1
1
|
const btTypes = require('../btree/types/module.f.cjs')
|
|
2
2
|
const btree = require('../btree/module.f.cjs')
|
|
3
|
-
const {
|
|
3
|
+
const {
|
|
4
|
+
find: { find, isFound },
|
|
5
|
+
remove: { remove: btreeRemove },
|
|
6
|
+
set: { set: btreeSet },
|
|
7
|
+
/** @type {(s: StringSet) => list.List<string>} */
|
|
8
|
+
values,
|
|
9
|
+
} = btree
|
|
4
10
|
const { stringCmp } = require("../function/compare/module.f.cjs")
|
|
5
11
|
const list = require('../list/module.f.cjs')
|
|
12
|
+
const { reduce } = list
|
|
6
13
|
const { compose } = require('../function/module.f.cjs')
|
|
7
14
|
|
|
8
15
|
/** @typedef {btTypes.Tree<string>} StringSet */
|
|
9
16
|
|
|
10
17
|
/** @type {(value: string) => (set: StringSet) => boolean} */
|
|
11
|
-
const contains = value => s => s !== undefined &&
|
|
18
|
+
const contains = value => s => s !== undefined && isFound(find(stringCmp(value))(s).first)
|
|
12
19
|
|
|
13
20
|
/** @type {(value: string) => (s: StringSet) => StringSet} */
|
|
14
|
-
const set = value =>
|
|
15
|
-
|
|
16
|
-
/** @type {(s: StringSet) => list.List<string>} */
|
|
17
|
-
const values = btree.values
|
|
21
|
+
const set = value => btreeSet(stringCmp(value))(value)
|
|
18
22
|
|
|
19
|
-
const fromValues =
|
|
23
|
+
const fromValues = reduce(set)(undefined)
|
|
20
24
|
|
|
21
25
|
/** @type {(value: string) => (s: StringSet) => StringSet} */
|
|
22
|
-
const remove = compose(stringCmp)(
|
|
26
|
+
const remove = compose(stringCmp)(btreeRemove)
|
|
23
27
|
|
|
24
28
|
module.exports = {
|
|
25
29
|
/** @readonly */
|
|
File without changes
|