functionalscript 0.0.334 → 0.0.335

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.
@@ -1,7 +1,6 @@
1
1
  const package_ = require('../package/index.js')
2
2
  const module_ = require('../module/index.js')
3
3
  const function_ = require('../module/function/index.js')
4
- const { todo } = require('../../dev/index.js')
5
4
  const map = require('../../types/map/index.js')
6
5
  const object = require('../../types/object/index.js')
7
6
  const path = require('../path/index.js')
@@ -60,10 +59,10 @@ const getOrBuild = compile => packageGet => moduleMapInterface => {
60
59
  /** @type {(e: module_.Error) => (m: M) => Result<M>} */
61
60
  const error = e => set(['error', e])
62
61
  // check compilation
63
- const j = compile(source)
64
- if (j[0] === 'error') { return error(['compilation error', j[1]])(moduleMap) }
62
+ const [kind, result] = compile(source)
63
+ if (kind === 'error') { return error(['compilation error', result])(moduleMap) }
65
64
  // build
66
- const [r, [requireMap, moduleMap2]] = j[1](require_)([undefined, moduleMap])
65
+ const [r, [requireMap, moduleMap2]] = result(require_)([undefined, moduleMap])
67
66
  const x = r[0] === 'error' ?
68
67
  error(['runtime error', r[1]]) :
69
68
  set(['ok', { exports: r[1], requireMap: object.fromMap(requireMap) }])
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "functionalscript",
3
- "version": "0.0.334",
3
+ "version": "0.0.335",
4
4
  "description": "FunctionalScript is a functional subset of JavaScript",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -97,26 +97,24 @@ const find = c => {
97
97
  }
98
98
 
99
99
  /** @type {<T>(first: First<T>) => boolean} */
100
- const isFound = first => {
101
- switch (first[0]) {
100
+ const isFound = ([i]) => {
101
+ switch (i) {
102
102
  case 1: case 3: { return true }
103
103
  default: { return false }
104
104
  }
105
105
  }
106
106
 
107
107
  /** @type {<T>(first: First<T>) => T | undefined} */
108
- const value = first => {
109
- switch (first[0]) {
108
+ const value = ([i, r]) => {
109
+ switch (i) {
110
110
  case 1: {
111
- const x = first[1]
112
- switch (x.length) {
113
- case 1: case 2: { return x[0] }
114
- default: { return x[1] }
111
+ switch (r.length) {
112
+ case 1: case 2: { return r[0] }
113
+ default: { return r[1] }
115
114
  }
116
115
  }
117
116
  case 3: {
118
- const x = first[1]
119
- return x.length === 2 ? x[1] : x[3]
117
+ return r.length === 2 ? r[1] : r[3]
120
118
  }
121
119
  default: {
122
120
  return undefined
@@ -93,24 +93,20 @@ const initValue1 = a => n => {
93
93
  */
94
94
 
95
95
  /** @type {<A, T>(ms: array.Array2<Merge<A, T>>) => (i: find.PathItem<T>) => (a: A) => Branch<T>} */
96
- const reduceX = ms => i => a => {
96
+ const reduceX = ms => ([i, n]) => a => {
97
97
  const [m0, m2] = ms
98
98
  /** @typedef {typeof ms extends array.Array2<Merge<infer A, infer T>> ? [A,T] : never} AT */
99
99
  /** @typedef {AT[0]} A */
100
100
  /** @typedef {AT[1]} T */
101
101
  /** @type {(m: Merge<A, T>) => Branch<T>} */
102
102
  const f = m => {
103
- const n = i[1]
104
103
  const ra = m(a)
105
104
  return n.length === 3 ? ra(n) : [...ra([n[0], n[1], n[2]]), n[3], n[4]]
106
105
  }
107
- switch (i[0]) {
106
+ switch (i) {
108
107
  case 0: { return f(m0) }
109
108
  case 2: { return f(m2) }
110
- case 4: {
111
- const n = i[1]
112
- return [n[0], n[1], ...m2(a)([n[2], n[3], n[4]])]
113
- }
109
+ case 4: { return [n[0], n[1], ...m2(a)([n[2], n[3], n[4]])] }
114
110
  }
115
111
  }
116
112
 
@@ -129,9 +125,9 @@ const nodeRemove = c => node => {
129
125
  const [v, p] = path(/** @type {find.Path<T>} */(undefined))(n)
130
126
  return { first: p.first, tail: list.concat(p.tail)({ first: f(v), tail }) }
131
127
  }
132
- switch (first[0]) {
128
+ const [i, n] = first
129
+ switch (i) {
133
130
  case 1: {
134
- const n = first[1]
135
131
  switch (n.length) {
136
132
  case 1: { return { first: undefined, tail } }
137
133
  case 2: { return { first: [n[1]], tail } }
@@ -140,7 +136,6 @@ const nodeRemove = c => node => {
140
136
  }
141
137
  }
142
138
  case 3: {
143
- const n = first[1]
144
139
  switch (n.length) {
145
140
  case 2: { return { first: [n[0]], tail } }
146
141
  case 5: { return branch(n[4])(v => [4, [n[0], n[1], n[2], v, n[4]]]) }
@@ -5,31 +5,28 @@ const list = require('../../list/index.js')
5
5
 
6
6
  /**
7
7
  * @template T
8
- * @typedef {_.Branch1<T> | _.Branch3<T>} Bracnh1To3
8
+ * @typedef {_.Branch1<T> | _.Branch3<T>} Branch1To3
9
9
  */
10
10
 
11
- /** @type {<T>(b: _.Branch5<T> | _.Branch7<T>) => Bracnh1To3<T>} */
11
+ /** @type {<T>(b: _.Branch5<T> | _.Branch7<T>) => Branch1To3<T>} */
12
12
  const b57 = b => b.length === 5 ? [b] : [[b[0], b[1], b[2]], b[3], [b[4], b[5], b[6]]]
13
13
 
14
- /** @type {<T>(i: find.PathItem<T>) => (a: Bracnh1To3<T>) => Bracnh1To3<T>} */
15
- const reduce = i => a => {
16
- switch (i[0]) {
14
+ /** @type {<T>(i: find.PathItem<T>) => (a: Branch1To3<T>) => Branch1To3<T>} */
15
+ const reduce = ([i, x]) => a => {
16
+ switch (i) {
17
17
  case 0: {
18
- const x = i[1]
19
18
  switch (x.length) {
20
19
  case 3: { return [[...a, x[1], x[2]]] }
21
20
  case 5: { return b57([...a, x[1], x[2], x[3], x[4]]) }
22
21
  }
23
22
  }
24
23
  case 2: {
25
- const x = i[1]
26
24
  switch (x.length) {
27
25
  case 3: { return [[x[0], x[1], ...a]] }
28
26
  case 5: { return b57([x[0], x[1], ...a, x[3], x[4]]) }
29
27
  }
30
28
  }
31
29
  case 4: {
32
- const x = i[1]
33
30
  return b57([x[0], x[1], x[2], x[3], ...a])
34
31
  }
35
32
  }
@@ -38,13 +35,13 @@ const reduce = i => a => {
38
35
  /** @type {<T>(c: cmp.Compare<T>) => (value: T) => (node: _.Node<T>) => _.Node<T>} */
39
36
  const nodeSet = c => value => node => {
40
37
  const { first, tail } = find.find(c)(node)
38
+ const [i, x] = first;
41
39
  /** @typedef {typeof value} T */
42
- /** @type {() => Bracnh1To3<T>} */
40
+ /** @type {() => Branch1To3<T>} */
43
41
  const f = () => {
44
- switch (first[0]) {
42
+ switch (i) {
45
43
  case 0: {
46
44
  // insert
47
- const x = first[1]
48
45
  switch (x.length) {
49
46
  case 1: { return [[value, x[0]]] }
50
47
  case 2: { return [[value], x[0], [x[1]]] }
@@ -52,7 +49,6 @@ const nodeSet = c => value => node => {
52
49
  }
53
50
  case 1: {
54
51
  // replace
55
- const x = first[1];
56
52
  switch (x.length) {
57
53
  case 1: { return [[value]] }
58
54
  case 2: { return [[value, x[1]]] }
@@ -62,7 +58,6 @@ const nodeSet = c => value => node => {
62
58
  }
63
59
  case 2: {
64
60
  // insert
65
- const x = first[1];
66
61
  switch (x.length) {
67
62
  case 1: { return [[x[0], value]] }
68
63
  case 2: { return [[x[0]], value, [x[1]]] }
@@ -70,7 +65,6 @@ const nodeSet = c => value => node => {
70
65
  }
71
66
  case 3: {
72
67
  // replace
73
- const x = first[1];
74
68
  switch (x.length) {
75
69
  case 2: { return [[x[0], value]] }
76
70
  case 5: { return [[x[0], x[1], x[2], value, x[4]]]}
@@ -78,7 +72,7 @@ const nodeSet = c => value => node => {
78
72
  }
79
73
  case 4: {
80
74
  // insert
81
- const [v0, v1] = first[1];
75
+ const [v0, v1] = x;
82
76
  return [[v0], v1, [value]]
83
77
  }
84
78
  }
@@ -21,9 +21,9 @@ const ok = value => ['ok', value]
21
21
  const error = e => ['error', e]
22
22
 
23
23
  /** @type {<T, E>(r: Result<T, E>) => T} */
24
- const unwrap = result => {
25
- if (result[0] === 'error') { throw result[1] }
26
- return result[1]
24
+ const unwrap = ([kind, v]) => {
25
+ if (kind === 'error') { throw v }
26
+ return v
27
27
  }
28
28
 
29
29
  module.exports = {