functionalscript 0.0.150 → 0.0.154

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/index.js CHANGED
@@ -28,48 +28,18 @@
28
28
  /** @type {(_: string) => never} */
29
29
  const panic = message => { throw message }
30
30
 
31
- /**
32
- * @template T
33
- * @typedef {{
34
- * readonly get: (_: string) => T|undefined
35
- * readonly set: (_: string) => (_: T) => Dictionary<T>
36
- * readonly entries: () => Iterable<[string, T]>
37
- * }} Dictionary
38
- */
39
-
40
- /**
41
- * @template T
42
- * @typedef {{
43
- * readonly [_ in string]: T
44
- * }} InternalMap
45
- */
46
-
47
- const dictionary = {
48
- get: () => undefined,
49
- /** @type {(_: string) => <T>(_: T) => Dictionary<T>} */
50
- set: key => value => createDictionary({[key]: value}),
51
- entries: () => []
52
- }
53
-
54
- /** @type {<T>(_: InternalMap<T>) => Dictionary<T>} */
55
- const createDictionary = internal => ({
56
- get: key => internal[key],
57
- set: key => value => createDictionary({ ...internal, [key]: value }),
58
- entries: () => Object.entries(internal),
59
- })
60
-
61
31
  /** @type {<A>(_: A) => <B>(_: B) => [A, B]} */
62
32
  const tuple2 = a => b => [a, b]
63
33
 
64
- /** @type {<T>(_: (_: string) => T) => (_: Dictionary<T>) => (_: string) => [T, Dictionary<T>]} */
65
- const cache = f => d => k => {
66
- const set = () => {
67
- const r = f(k)
68
- return tuple2(r)(d.set(k)(r))
69
- }
70
- const result = d.get(k)
71
- return result !== undefined ? [result, d] : set()
72
- }
34
+ // /** @type {<T>(_: (_: string) => T) => (_: Dictionary<T>) => (_: string) => [T, Dictionary<T>]} */
35
+ // const cache = f => d => k => {
36
+ // const set = () => {
37
+ // const r = f(k)
38
+ // return tuple2(r)(d.set(k)(r))
39
+ // }
40
+ // const result = d.get(k)
41
+ // return result !== undefined ? [result, d] : set()
42
+ // }
73
43
 
74
44
  /**
75
45
  * @template T
@@ -133,8 +103,6 @@ module.exports = {
133
103
  /** @type {(_: string) => (_: boolean) => void} */
134
104
  panic_if: message => condition => condition ? panic(message) : undefined,
135
105
 
136
- dictionary,
137
-
138
106
  /** @type {<T>(_: Continuation<T>) => T} */
139
107
  trampoline: continuation => {
140
108
  while (true) {
@@ -165,8 +133,6 @@ module.exports = {
165
133
 
166
134
  optionMap,
167
135
 
168
- cache,
169
-
170
136
  /** @type {<T>(_: T[]) => T[]|undefined} */
171
137
  tail: a => a.length === 0 ? undefined : uncheckTail(a),
172
138
 
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,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 struct: () => []
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
- struct: () => [],
64
+ root: undefined
65
65
  }
66
66
 
67
67
  module.exports = {
package/lib/map/test.js CHANGED
@@ -40,16 +40,28 @@ const lib = require('..')
40
40
  // console.log(Array.from(m.entries()))
41
41
  }
42
42
 
43
+ {
44
+ const m = map.set('x')(12).set('y')(44)
45
+ lib.panic_if('map.get(\'x\')')(m.get('x') !== 12)
46
+ lib.panic_if('map.get(\'y\')')(m.get('y') !== 44)
47
+ lib.panic_if('map.get(\'a\')')(m.get('a') !== undefined)
48
+ const entries = Array.from(m.entries())
49
+ lib.panic_if('map.entries()')(entries.length !== 2)
50
+ }
51
+
52
+
43
53
  {
44
54
  /** @type {import('.').Map<number>} */
45
55
  let m = map
46
- for (let i = 0; i < 100; ++i) {
56
+ for (let i = 0; i < 1_000_000; ++i) {
47
57
  m = m.set((i*i).toString())(i)
58
+ /*
48
59
  console.log()
49
60
  console.log(`# ${i}`)
50
61
  console.log()
51
62
  for (const e of m.struct()) {
52
63
  console.log(e)
53
64
  }
65
+ */
54
66
  }
55
67
  }
package/lib/test.js CHANGED
@@ -3,11 +3,3 @@ const lib = require('./index')
3
3
  require('./iterable/test')
4
4
  require('./map/test')
5
5
 
6
- {
7
- const map = lib.dictionary.set('x')(12).set('y')(44)
8
- lib.panic_if('map.get(\'x\')')(map.get('x') !== 12)
9
- lib.panic_if('map.get(\'y\')')(map.get('y') !== 44)
10
- lib.panic_if('map.get(\'a\')')(map.get('a') !== undefined)
11
- const entries = Array.from(map.entries())
12
- lib.panic_if('map.entries()')(entries.length !== 2)
13
- }
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.150",
3
+ "version": "0.0.154",
4
4
  "description": "FunctionalScript is a functional subset of JavaScript",
5
5
  "main": "index.js",
6
6
  "scripts": {