functionalscript 0.0.151 → 0.0.155

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 CHANGED
@@ -1,5 +1,5 @@
1
1
  const { optionMap } = require("..")
2
- const { getVisitor, setVisitor, values, struct } = require("../tree")
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 struct: () => Iterable<string>
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 = node => ({
41
- get: name => optionMap(([,value]) => value)(getVisitor(cmp(name))(node)),
42
- set: name => value => {
43
- const result = setVisitor(cmp(name))(() => [name, value])(node)
40
+ const create = root => ({
41
+ get: name => optionMap(([,value]) => value)(getVisitor(cmp(name))(root)),
42
+ set: 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(node),
49
- struct: () => struct(node),
48
+ entries: () => values(root),
49
+ root,
50
50
  })
51
51
 
52
52
  /**
@@ -54,17 +54,17 @@ 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 struct: () => []
57
+ * readonly root: undefined
58
58
  * }}
59
59
  */
60
- const map = {
60
+ const empty = {
61
61
  get: () => undefined,
62
62
  set: name => value => create([[name, value]]),
63
63
  entries: () => [],
64
- struct: () => [],
64
+ root: undefined
65
65
  }
66
66
 
67
67
  module.exports = {
68
68
  /** @readonly */
69
- map,
69
+ empty,
70
70
  }
package/lib/map/test.js CHANGED
@@ -1,8 +1,8 @@
1
- const { map } = require('.')
1
+ const { empty } = require('.')
2
2
  const lib = require('..')
3
3
 
4
4
  {
5
- let m = map.set('a')(1)
5
+ let m = empty.set('a')(1)
6
6
 
7
7
  if (m.get('a') !== 1) { throw 'error' }
8
8
  if (m.get('b') !== undefined) { throw 'error' }
@@ -41,7 +41,7 @@ const lib = require('..')
41
41
  }
42
42
 
43
43
  {
44
- const m = map.set('x')(12).set('y')(44)
44
+ const m = empty.set('x')(12).set('y')(44)
45
45
  lib.panic_if('map.get(\'x\')')(m.get('x') !== 12)
46
46
  lib.panic_if('map.get(\'y\')')(m.get('y') !== 44)
47
47
  lib.panic_if('map.get(\'a\')')(m.get('a') !== undefined)
@@ -52,8 +52,8 @@ const lib = require('..')
52
52
 
53
53
  {
54
54
  /** @type {import('.').Map<number>} */
55
- let m = map
56
- for (let i = 0; i < 100; ++i) {
55
+ let m = empty
56
+ for (let i = 0; i < 1_000_000; ++i) {
57
57
  m = m.set((i*i).toString())(i)
58
58
  /*
59
59
  console.log()
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
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "functionalscript",
3
- "version": "0.0.151",
3
+ "version": "0.0.155",
4
4
  "description": "FunctionalScript is a functional subset of JavaScript",
5
5
  "main": "index.js",
6
6
  "scripts": {