functionalscript 0.0.389 → 0.0.392
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 +126 -118
- 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 +1 -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/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/list/module.f.cjs +38 -12
- package/types/map/module.f.cjs +11 -10
- package/types/module.f.cjs +1 -1
- 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
|
@@ -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
|
|
package/types/list/module.f.cjs
CHANGED
|
@@ -1,6 +1,18 @@
|
|
|
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
|
+
addition,
|
|
5
|
+
min: minOp,
|
|
6
|
+
max: maxOp,
|
|
7
|
+
join: joinOp,
|
|
8
|
+
concat: concatOp,
|
|
9
|
+
counter,
|
|
10
|
+
logicalNot,
|
|
11
|
+
strictEqual,
|
|
12
|
+
stateScanToScan,
|
|
13
|
+
reduceToScan,
|
|
14
|
+
foldToScan
|
|
15
|
+
} = operator
|
|
4
16
|
|
|
5
17
|
/**
|
|
6
18
|
* @template T
|
|
@@ -99,10 +111,12 @@ const iterable = list => ({
|
|
|
99
111
|
}
|
|
100
112
|
})
|
|
101
113
|
|
|
114
|
+
const { from } = Array
|
|
115
|
+
|
|
102
116
|
/** @type {<T>(list: List<T>) => readonly T[]} */
|
|
103
117
|
const toArray = list => {
|
|
104
118
|
const u = trampoline(list)
|
|
105
|
-
return u instanceof Array ? u :
|
|
119
|
+
return u instanceof Array ? u : from(iterable(u))
|
|
106
120
|
}
|
|
107
121
|
|
|
108
122
|
/** @type {<I, O>(step: (n: NonEmpty<I>) => List<O>) => (input: List<I>) => Thunk<O>} */
|
|
@@ -192,17 +206,23 @@ const last = first => tail => {
|
|
|
192
206
|
/** @type {<D>(def: D) => <T>(f: (value: T) => boolean) => (input: List<T>) => D|T} */
|
|
193
207
|
const find = def => f => input => first(def)(filter(f)(input))
|
|
194
208
|
|
|
209
|
+
const findTrue = find(false)
|
|
210
|
+
|
|
195
211
|
/** @type {(input: List<boolean>) => boolean} */
|
|
196
|
-
const some = input =>
|
|
197
|
-
(false)
|
|
212
|
+
const some = input => findTrue
|
|
198
213
|
(/** @type {(_: boolean) => boolean} */(identity))
|
|
199
214
|
(input)
|
|
200
215
|
|
|
216
|
+
/** @type {<T>(f: List<T>) => Thunk<boolean>} */
|
|
217
|
+
const mapTrue = map(() => true)
|
|
218
|
+
|
|
201
219
|
/** @type {<T>(input: List<T>) => boolean} */
|
|
202
|
-
const isEmpty = input => !some(
|
|
220
|
+
const isEmpty = input => !some(mapTrue(input))
|
|
221
|
+
|
|
222
|
+
const mapNot = map(logicalNot)
|
|
203
223
|
|
|
204
224
|
/** @type {(input: List<boolean>) => boolean} */
|
|
205
|
-
const every = input => !some(
|
|
225
|
+
const every = input => !some(mapNot(input))
|
|
206
226
|
|
|
207
227
|
/** @type {<T>(value: T) => (sequence: List<T>) => boolean} */
|
|
208
228
|
const includes = value => input => some(map(strictEqual(value))(input))
|
|
@@ -244,17 +264,19 @@ const reduce = op => init => input => last(init)(reduceScan(op)(init)(input))
|
|
|
244
264
|
/** @type {<T>(op: operator.Fold<T>) => <D>(def: D) => (input: List<T>) => D|T} */
|
|
245
265
|
const fold = op => def => input => last(def)(scan(foldToScan(op))(input))
|
|
246
266
|
|
|
247
|
-
const sum = fold(
|
|
267
|
+
const sum = fold(addition)(0)
|
|
248
268
|
|
|
249
|
-
const min = fold(
|
|
269
|
+
const min = fold(minOp)(undefined)
|
|
250
270
|
|
|
251
|
-
const max = fold(
|
|
271
|
+
const max = fold(maxOp)(undefined)
|
|
252
272
|
|
|
253
273
|
/** @type {(separator: string) => (input: List<string>) => string} */
|
|
254
|
-
const join = separator => fold(
|
|
274
|
+
const join = separator => fold(joinOp(separator))('')
|
|
275
|
+
|
|
276
|
+
const stringConcat = fold(concatOp)('')
|
|
255
277
|
|
|
256
278
|
/** @type {<T>(input: List<T>) => number} */
|
|
257
|
-
const length = reduce(
|
|
279
|
+
const length = reduce(counter)(0)
|
|
258
280
|
|
|
259
281
|
/**
|
|
260
282
|
* @template T
|
|
@@ -267,7 +289,9 @@ const entryOperator = index => value => [[index, value], index + 1]
|
|
|
267
289
|
/** @type {<T>(input: List<T>) => Thunk<Entry<T>>} */
|
|
268
290
|
const entries = input => {
|
|
269
291
|
/** @typedef {typeof input extends List<infer T> ? T : never} T */
|
|
270
|
-
|
|
292
|
+
/** @type {operator.StateScan<T, Number, Entry<T>>} */
|
|
293
|
+
const o = entryOperator
|
|
294
|
+
return stateScan(o)(0)(input)
|
|
271
295
|
}
|
|
272
296
|
|
|
273
297
|
/** @type {<T>(value: T) => (prior: List<T>) => List<T>} */
|
|
@@ -364,6 +388,8 @@ module.exports = {
|
|
|
364
388
|
/** @readonly */
|
|
365
389
|
join,
|
|
366
390
|
/** @readonly */
|
|
391
|
+
stringConcat,
|
|
392
|
+
/** @readonly */
|
|
367
393
|
length,
|
|
368
394
|
/** @readonly */
|
|
369
395
|
entries,
|
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
|
@@ -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
|