functionalscript 0.0.285 → 0.0.286

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "functionalscript",
3
- "version": "0.0.285",
3
+ "version": "0.0.286",
4
4
  "description": "FunctionalScript is a functional subset of JavaScript",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -54,6 +54,18 @@ const seq = require('../list')
54
54
 
55
55
  /** @typedef {0|1|2|3|4} Index5 */
56
56
 
57
+ /**
58
+ * @template T
59
+ * @typedef {T extends Array1<infer _> ? Index1 :
60
+ * T extends Array2<infer _> ? Index2 :
61
+ * T extends Array3<infer _> ? Index3 :
62
+ * T extends Array4<infer _> ? Index4 :
63
+ * T extends Array5<infer _> ? Index5 :
64
+ * T extends readonly (infer _)[] ? number :
65
+ * never
66
+ * } KeyOf
67
+ */
68
+
57
69
  /** @type {<T>(_: readonly T[]) => readonly T[]} */
58
70
  const uncheckTail = a => a.slice(1)
59
71
 
@@ -1,7 +1,7 @@
1
1
  const _ = require('..')
2
- const { todo } = require('../../../dev')
3
2
  const list = require('../../list')
4
3
  const cmp = require('../../function/compare')
4
+ const array = require('../../array')
5
5
 
6
6
  /**
7
7
  * @template T
@@ -56,7 +56,10 @@ const child = item => {
56
56
 
57
57
  /**
58
58
  * @template T
59
- * @typedef {readonly[First<T>, Path<T>]} Result<T>
59
+ * @typedef {{
60
+ * readonly first: First<T>,
61
+ * readonly tail: Path<T>
62
+ * }} Result<T>
60
63
  */
61
64
 
62
65
  /** @type {<T>(c: cmp.Compare<T>) => (node: _.Node<T>) => Result<T>} */
@@ -66,23 +69,28 @@ const find = c => {
66
69
  /** @typedef {typeof c extends cmp.Compare<infer T> ? T : never} T */
67
70
  /** @type {(prior: Path<T>) => (node: _.Node<T>) => Result<T>} */
68
71
  const f = tail => node => {
69
- /** @type {(first: PathItem<T>) => Result<T>} */
70
- const append = first => f({ first, tail })(child(first))
72
+ /** @type {(index: array.KeyOf<typeof node>) => Result<T>} */
73
+ const append = index => {
74
+ const first = /** @type {PathItem<T>} */([index, node])
75
+ return f({ first, tail })(child(first))
76
+ }
77
+ /** @type {(index: array.KeyOf<typeof node>) => Result<T>} */
78
+ const done = index => ({ first: /** @type {First<T>} */([index, node]), tail })
71
79
  switch (node.length) {
72
- case 1: { return [[i3(node[0]), node], tail] }
73
- case 2: { return [[i5(node), node], tail] }
80
+ case 1: { return done(i3(node[0])) }
81
+ case 2: { return done(i5(node)) }
74
82
  case 3: {
75
83
  const i = i3(node[1])
76
84
  switch (i) {
77
- case 0: case 2: { return append([i, node]) }
78
- case 1: { return [[i, node], tail] }
85
+ case 0: case 2: { return append(i) }
86
+ case 1: { return done(i) }
79
87
  }
80
88
  }
81
89
  case 5: {
82
90
  const i = i5([node[1], node[3]])
83
91
  switch (i) {
84
- case 0: case 2: case 4: { return append([i, node]) }
85
- case 1: case 3: { return [[i, node], tail]}
92
+ case 0: case 2: case 4: { return append(i) }
93
+ case 1: case 3: { return done(i) }
86
94
  }
87
95
  }
88
96
  }
@@ -7,9 +7,6 @@ const { stringCmp } = require('../../function/compare')
7
7
 
8
8
  const jsonStr = json.stringify(sort)
9
9
 
10
- // /** @type {(sequence: list.List<json.Unknown>) => string} */
11
- // const arrayStr = sequence => jsonStr(list.toArray(sequence))
12
-
13
10
  /** @type {(node: btree.Node<string>) => (value: string) => btree.Node<string>} */
14
11
  const set = node => value => {
15
12
  const result = btree.setVisitor(stringCmp(value))(node)(() => value)
@@ -20,7 +17,7 @@ const set = node => value => {
20
17
  }
21
18
 
22
19
  /** @type {(r: _.Result<json.Unknown>) => string} */
23
- const str = ([r, path]) => jsonStr([r[0], list.toArray(list.map(x => x[0])(path))])
20
+ const str = r => jsonStr(list.toArray(list.map(x => x[0])(r)))
24
21
 
25
22
  /** @type {(i: string) => (m: btree.Node<string>) => string} */
26
23
  const find = i => m => str(_.find(stringCmp(i))(m))
@@ -37,86 +34,86 @@ const find = i => m => str(_.find(stringCmp(i))(m))
37
34
  //
38
35
  {
39
36
  const r = find("0")(_map)
40
- if (r !== '[0,[0,0]]') { throw r }
37
+ if (r !== '[0,0,0]') { throw r }
41
38
  }
42
39
  {
43
40
  const r = find("1")(_map)
44
- if (r !== '[1,[0,0]]') { throw r }
41
+ if (r !== '[1,0,0]') { throw r }
45
42
  }
46
43
  {
47
44
  const r = find("10")(_map)
48
- if (r !== '[2,[0,0]]') { throw r }
45
+ if (r !== '[2,0,0]') { throw r }
49
46
  }
50
47
  {
51
48
  const r = find("100")(_map)
52
- if (r !== '[3,[0,0]]') { throw r }
49
+ if (r !== '[3,0,0]') { throw r }
53
50
  }
54
51
  {
55
52
  const r = find("12")(_map)
56
- if (r !== '[4,[0,0]]') { throw r }
53
+ if (r !== '[4,0,0]') { throw r }
57
54
  }
58
55
  {
59
56
  const r = find("16")(_map)
60
- if (r !== '[1,[0]]') { throw r }
57
+ if (r !== '[1,0]') { throw r }
61
58
  }
62
59
  {
63
60
  const r = find("17")(_map)
64
- if (r !== '[0,[2,0]]') { throw r }
61
+ if (r !== '[0,2,0]') { throw r }
65
62
  }
66
63
  {
67
64
  const r = find("25")(_map)
68
- if (r !== '[1,[2,0]]') { throw r }
65
+ if (r !== '[1,2,0]') { throw r }
69
66
  }
70
67
  {
71
68
  const r = find("26")(_map)
72
- if (r !== '[2,[2,0]]') { throw r }
69
+ if (r !== '[2,2,0]') { throw r }
73
70
  }
74
71
  {
75
72
  const r = find("36")(_map)
76
- if (r !== '[3,[2,0]]') { throw r }
73
+ if (r !== '[3,2,0]') { throw r }
77
74
  }
78
75
  {
79
76
  const r = find("37")(_map)
80
- if (r !== '[4,[2,0]]') { throw r }
77
+ if (r !== '[4,2,0]') { throw r }
81
78
  }
82
79
  {
83
80
  const r = find("4")(_map)
84
- if (r !== '[1,[]]') { throw r }
81
+ if (r !== '[1]') { throw r }
85
82
  }
86
83
  {
87
84
  const r = find("41")(_map)
88
- if (r !== '[0,[0,2]]') { throw r }
85
+ if (r !== '[0,0,2]') { throw r }
89
86
  }
90
87
  {
91
88
  const r = find("49")(_map)
92
- if (r !== '[1,[0,2]]') { throw r }
89
+ if (r !== '[1,0,2]') { throw r }
93
90
  }
94
91
  {
95
92
  const r = find("5")(_map)
96
- if (r !== '[2,[0,2]]') { throw r }
93
+ if (r !== '[2,0,2]') { throw r }
97
94
  }
98
95
  {
99
96
  const r = find("64")(_map)
100
- if (r !== '[1,[2]]') { throw r }
97
+ if (r !== '[1,2]') { throw r }
101
98
  }
102
99
  {
103
100
  const r = find("65")(_map)
104
- if (r !== '[0,[2,2]]') { throw r }
101
+ if (r !== '[0,2,2]') { throw r }
105
102
  }
106
103
  {
107
104
  const r = find("81")(_map)
108
- if (r !== '[1,[2,2]]') { throw r }
105
+ if (r !== '[1,2,2]') { throw r }
109
106
  }
110
107
  {
111
108
  const r = find("85")(_map)
112
- if (r !== '[2,[2,2]]') { throw r }
109
+ if (r !== '[2,2,2]') { throw r }
113
110
  }
114
111
  {
115
112
  const r = find("9")(_map)
116
- if (r !== '[3,[2,2]]') { throw r }
113
+ if (r !== '[3,2,2]') { throw r }
117
114
  }
118
115
  {
119
116
  const r = find("91")(_map)
120
- if (r !== '[4,[2,2]]') { throw r }
117
+ if (r !== '[4,2,2]') { throw r }
121
118
  }
122
119
  }