functionalscript 0.0.152 → 0.0.153
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/lib/map/index.js +9 -9
- package/lib/map/test.js +2 -0
- package/lib/tree/index.js +0 -42
- package/package.json +1 -1
package/lib/map/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const { optionMap } = require("..")
|
|
2
|
-
const { getVisitor, setVisitor, values
|
|
2
|
+
const { getVisitor, setVisitor, values } = require("../tree")
|
|
3
3
|
|
|
4
4
|
/** @typedef {import("../tree/cmp").Sign} Sign */
|
|
5
5
|
|
|
@@ -29,7 +29,7 @@ const { getVisitor, setVisitor, values, struct } = require("../tree")
|
|
|
29
29
|
* readonly get: (name: string) => T|undefined
|
|
30
30
|
* readonly set: (name: string) => (value: T) => Map<T>
|
|
31
31
|
* readonly entries: () => Iterable<Entry<T>>
|
|
32
|
-
* readonly
|
|
32
|
+
* readonly root: undefined|TNode<Entry<T>>
|
|
33
33
|
* }} Map
|
|
34
34
|
*/
|
|
35
35
|
|
|
@@ -37,16 +37,16 @@ const { getVisitor, setVisitor, values, struct } = require("../tree")
|
|
|
37
37
|
const cmp = a => ([b]) => a < b ? -1 : a === b ? 0 : 1
|
|
38
38
|
|
|
39
39
|
/** @type {<T>(node: TNode<Entry<T>>) => Map<T>} */
|
|
40
|
-
const create =
|
|
41
|
-
get: name => optionMap(([,value]) => value)(getVisitor(cmp(name))(
|
|
40
|
+
const create = root => ({
|
|
41
|
+
get: name => optionMap(([,value]) => value)(getVisitor(cmp(name))(root)),
|
|
42
42
|
set: name => value => {
|
|
43
|
-
const result = setVisitor(cmp(name))(() => [name, value])(
|
|
43
|
+
const result = setVisitor(cmp(name))(() => [name, value])(root)
|
|
44
44
|
if ('replace' in result) { return create(result.replace) }
|
|
45
45
|
if ('overflow' in result) { return create(result.overflow) }
|
|
46
46
|
throw ''
|
|
47
47
|
},
|
|
48
|
-
entries: () => values(
|
|
49
|
-
|
|
48
|
+
entries: () => values(root),
|
|
49
|
+
root,
|
|
50
50
|
})
|
|
51
51
|
|
|
52
52
|
/**
|
|
@@ -54,14 +54,14 @@ const create = node => ({
|
|
|
54
54
|
* readonly get: (name: string) => undefined
|
|
55
55
|
* readonly set: (name: string) => <T>(value: T) => Map<T>
|
|
56
56
|
* readonly entries: () => []
|
|
57
|
-
* readonly
|
|
57
|
+
* readonly root: undefined
|
|
58
58
|
* }}
|
|
59
59
|
*/
|
|
60
60
|
const map = {
|
|
61
61
|
get: () => undefined,
|
|
62
62
|
set: name => value => create([[name, value]]),
|
|
63
63
|
entries: () => [],
|
|
64
|
-
|
|
64
|
+
root: undefined
|
|
65
65
|
}
|
|
66
66
|
|
|
67
67
|
module.exports = {
|
package/lib/map/test.js
CHANGED
|
@@ -55,11 +55,13 @@ const lib = require('..')
|
|
|
55
55
|
let m = map
|
|
56
56
|
for (let i = 0; i < 10; ++i) {
|
|
57
57
|
m = m.set((i*i).toString())(i)
|
|
58
|
+
/*
|
|
58
59
|
console.log()
|
|
59
60
|
console.log(`# ${i}`)
|
|
60
61
|
console.log()
|
|
61
62
|
for (const e of m.struct()) {
|
|
62
63
|
console.log(e)
|
|
63
64
|
}
|
|
65
|
+
*/
|
|
64
66
|
}
|
|
65
67
|
}
|
package/lib/tree/index.js
CHANGED
|
@@ -319,49 +319,7 @@ const values = node => ({
|
|
|
319
319
|
}
|
|
320
320
|
})
|
|
321
321
|
|
|
322
|
-
/**
|
|
323
|
-
* @typedef {{}}
|
|
324
|
-
*/
|
|
325
|
-
|
|
326
|
-
/** @type {(offset: string) => <T>(_: TNode<T>) => Iterable<string>} */
|
|
327
|
-
const struct = offset => node => ({
|
|
328
|
-
*[Symbol.iterator]() {
|
|
329
|
-
const next = `${offset} `
|
|
330
|
-
switch (node.length) {
|
|
331
|
-
case 1: {
|
|
332
|
-
yield `${offset}- [1]:`
|
|
333
|
-
yield `${next}- ${node[0]}`
|
|
334
|
-
return
|
|
335
|
-
}
|
|
336
|
-
case 2: {
|
|
337
|
-
yield `${offset}- [2]:`
|
|
338
|
-
yield `${next}- ${node[0]}`
|
|
339
|
-
yield `${next}- ${node[1]}`
|
|
340
|
-
return
|
|
341
|
-
}
|
|
342
|
-
case 3: {
|
|
343
|
-
yield `${offset}- [3]:`
|
|
344
|
-
yield* struct(next)(node[0])
|
|
345
|
-
yield `${next}- ${node[1]}`
|
|
346
|
-
yield* struct(next)(node[2])
|
|
347
|
-
return
|
|
348
|
-
}
|
|
349
|
-
default: {
|
|
350
|
-
yield `${offset}- [5]:`
|
|
351
|
-
yield* struct(next)(node[0])
|
|
352
|
-
yield `${next}- ${node[1]}`
|
|
353
|
-
yield* struct(next)(node[2])
|
|
354
|
-
yield `${next}- ${node[3]}`
|
|
355
|
-
yield* struct(next)(node[4])
|
|
356
|
-
return
|
|
357
|
-
}
|
|
358
|
-
}
|
|
359
|
-
}
|
|
360
|
-
})
|
|
361
|
-
|
|
362
322
|
module.exports = {
|
|
363
|
-
/** @readonly */
|
|
364
|
-
struct: struct(''),
|
|
365
323
|
/** @readonly */
|
|
366
324
|
values,
|
|
367
325
|
/**
|