functionalscript 0.0.239 → 0.0.240

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.
@@ -0,0 +1,55 @@
1
+ # Common.js
2
+
3
+ ```ts
4
+ // package/index.js
5
+
6
+ type PackageGet = (packageId: string) => Package | undefined
7
+ type Package = {
8
+ // returns a global package id.
9
+ readonly dependency: (localPackageId: string) => string | undefined
10
+ // returns source of the file.
11
+ readonly file: (localFileId: string) => string | undefined
12
+ }
13
+
14
+ // module/index.js
15
+
16
+ type ModuleMapInterface<M> = {
17
+ readonly at: (moduleId: string) => (moduleMap: M) => ModuleState | undefined
18
+ readonly insert: (moduleId: string) => (moduleState: ModuleState) => (moduleMap: M) => M
19
+ }
20
+
21
+ type ModuleState = readonly['ok', Module] | readonly['error', ModuleError] | readonly['building']
22
+
23
+ type Module = {
24
+ readonly exports: unknown
25
+ readonly requireMap: object.Map<string>
26
+ }
27
+
28
+ type ModuleError = 'file not found' | 'compile error' | 'runtime error' | 'circular reference'
29
+
30
+ type ModuleId = {
31
+ readonly packageId: string,
32
+ readonly path: readonly string[],
33
+ }
34
+
35
+ const moduleIdToString: (moduleId: ModuleId) => string;
36
+
37
+ // build/index.js
38
+
39
+ type BuildConfig<M> = {
40
+ readonly packageGet: PackageGet
41
+ readonly moduleMapInterface: ModuleMapInterface<M>
42
+ readonly moduleId: ModuleId
43
+ readonly moduleMap: M // mutable
44
+ }
45
+
46
+ type BuildState<M> = {
47
+ readonly packageGet: PackageGet
48
+ readonly moduleMapInterface: ModuleMapInterface<M>
49
+ readonly moduleId: ModuleId
50
+ readonly moduleMap: M // mutable
51
+ readonly ModuleRequireMap: map.Map<string> // mutable
52
+ }
53
+
54
+ const getOrBuild: <M>(buildConfig: BuildConfig<M>) => readonly[ModuleState, M];
55
+ ```
@@ -1,22 +1,35 @@
1
- const map = require('../../types/map')
2
1
  const object = require('../../types/object')
3
- const run = require('../run')
4
- const seq = require('../../types/sequence')
5
2
 
6
3
  /**
4
+ * @template M
7
5
  * @typedef {{
8
- * readonly map: object.Map<string>
9
- * readonly run: run.Module
10
- * }} Module
6
+ * readonly at: (moduleId: string) => (moduleMap: M) => ModuleState | undefined
7
+ * readonly insert: (moduleId: string) => (moduleState: ModuleState) => (moduleMap: M) => M
8
+ * }} ModuleMapInterface
11
9
  */
12
10
 
13
11
  /**
12
+ * @typedef {|
13
+ * readonly['ok', Module] |
14
+ * readonly['error', ModuleError] |
15
+ * readonly['building']
16
+ * } ModuleState
17
+ */
18
+
19
+ /**
14
20
  * @typedef {{
15
- * readonly map: map.Map<Module>
16
- * readonly order: seq.Sequence<string>
17
- * }} Cache
21
+ * readonly exports: unknown
22
+ * readonly requireMap: object.Map<string>
23
+ * }} Module
18
24
  */
19
25
 
20
- /** @typedef {(path: string) => string|undefined} ReadFile */
26
+ /**
27
+ * @typedef {|
28
+ * 'file not found' |
29
+ * 'compile error' |
30
+ * 'runtime error' |
31
+ * 'circular reference'
32
+ * } ModuleError
33
+ */
21
34
 
22
35
  module.exports = {}
@@ -20,9 +20,14 @@ const isPackageJson = j => {
20
20
  return true
21
21
  }
22
22
 
23
- /** @typedef {object.Map<string>} Files */
23
+ /**
24
+ * @typedef {{
25
+ * readonly dependency: (localPackageId: string) => string | undefined
26
+ * readonly file: (localFileId: string) => string | undefined
27
+ * }} Package
28
+ */
24
29
 
25
- /** @typedef {object.Map<dep.DependencyJson>} PackageMap */
30
+ /** @typedef {(packageId: string) => Package | undefined} PackageGet */
26
31
 
27
32
  module.exports = {
28
33
  /** @readonly */
@@ -1,7 +1,6 @@
1
1
  const cp = require('child_process')
2
2
  const fs = require('fs')
3
- const json = require('../../../json')
4
- const { isPackageJson } = require('../../../commonjs/package')
3
+ const package_json = require('../../../package.json')
5
4
 
6
5
  const b =cp.execSync('git log --oneline')
7
6
 
@@ -11,10 +10,6 @@ const v = `0.0.${r}`
11
10
 
12
11
  console.log(`version: ${v}`)
13
12
 
14
- const package_json = json.parse(fs.readFileSync('package.json').toString())
15
-
16
- if (!isPackageJson(package_json)) { throw 'error' }
17
-
18
13
  const x = { ...package_json, version: v }
19
14
 
20
15
  fs.writeFileSync('package.json', JSON.stringify(x, null, 2))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "functionalscript",
3
- "version": "0.0.239",
3
+ "version": "0.0.240",
4
4
  "description": "FunctionalScript is a functional subset of JavaScript",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -14,12 +14,19 @@
14
14
  },
15
15
  "author": "Natfoam",
16
16
  "license": "Apache-2.0",
17
+ "keywords": [
18
+ "lambda",
19
+ "functional-programming",
20
+ "closure",
21
+ "pure-functional",
22
+ "typescript"
23
+ ],
17
24
  "bugs": {
18
25
  "url": "https://github.com/functionalscript/functionalscript/issues"
19
26
  },
20
27
  "homepage": "https://github.com/functionalscript/functionalscript#readme",
21
28
  "devDependencies": {
22
- "@types/node": "^16.11.11",
29
+ "@types/node": "^16.11.12",
23
30
  "typescript": "^4.5.2"
24
31
  }
25
32
  }
package/tsconfig.json CHANGED
@@ -33,7 +33,7 @@
33
33
  // "typeRoots": [], /* Specify multiple folders that act like `./node_modules/@types`. */
34
34
  // "types": [], /* Specify type package names to be included without being referenced in a source file. */
35
35
  // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
36
- // "resolveJsonModule": true, /* Enable importing .json files */
36
+ "resolveJsonModule": true, /* Enable importing .json files */
37
37
  // "noResolve": true, /* Disallow `import`s, `require`s or `<reference>`s from expanding the number of files TypeScript should add to a project. */
38
38
 
39
39
  /* JavaScript Support */
@@ -129,41 +129,39 @@ const seq = require('../sequence')
129
129
  const split = ([n0, v1, n2, v3, n4, v5, n6]) => [[n0, v1, n2], v3, [n4, v5, n6]]
130
130
 
131
131
  /**
132
- * @type {<T>(overflow: (o: Branch3<T>) => Result<T>) =>
132
+ * @type {<T>(extend: (o: Branch3<T>) => Result<T>) =>
133
133
  * (replace: (r: Node<T>) => Node<T>) =>
134
134
  * (result: Result<T>) =>
135
135
  * Result<T>}
136
136
  */
137
- const merge = overflow => replace => result => {
137
+ const merge = extend => replace => result => {
138
138
  switch (result[0]) {
139
139
  case 'done': { return result }
140
140
  case 'replace': { return ['replace', replace(result[1])] }
141
- default: { return overflow(result[1]) }
141
+ default: { return extend(result[1]) }
142
142
  }
143
143
  }
144
144
 
145
- /**
146
- * @type {<T>(overflow: (o: Branch3<T>) => Branch5<T>) =>
147
- * (replace: (r: Node<T>) => Branch3<T>) =>
148
- * (result: Result<T>) =>
149
- * Result<T>}
150
- */
151
- const merge2 = overflow => merge(o => ['replace', overflow(o)])
152
-
153
- /**
154
- * @type {<T>(overflow: (o: Branch3<T>) => Branch7<T>) =>
155
- * (replace: (r: Node<T>) => Branch5<T>) =>
156
- * (result: Result<T>) =>
157
- * Result<T>}
158
- */
159
- const merge3 = overflow => merge(o => ['overflow', split(overflow(o))])
160
-
161
145
  /** @type {(visitor: Visitor) => <T>(cmp: Cmp<T>) => (init: Lazy<T>) => (node: Node<T>) => Result<T>} */
162
146
  const visit = ({ found, notFound }) => cmp => {
163
147
  const i3 = index3(cmp)
164
148
  const i5 = index5(cmp)
149
+ /** @typedef {typeof cmp extends Cmp<infer T> ? T : never} T */
150
+ /**
151
+ * @type {(extend: (o: Branch3<T>) => Branch5<T>) =>
152
+ * (replace: (r: Node<T>) => Branch3<T>) =>
153
+ * (result: Result<T>) =>
154
+ * Result<T>}
155
+ */
156
+ const merge2 = extend => merge(o => ['replace', extend(o)])
157
+ /**
158
+ * @type {(extend: (o: Branch3<T>) => Branch7<T>) =>
159
+ * (replace: (r: Node<T>) => Branch5<T>) =>
160
+ * (result: Result<T>) =>
161
+ * Result<T>}
162
+ */
163
+ const merge3 = extend => merge(o => ['overflow', split(extend(o))])
165
164
  return init => {
166
- /** @typedef {typeof cmp extends Cmp<infer T> ? T : never} T*/
167
165
  /** @type {(node: Node<T>) => Result<T>} */
168
166
  const f = node => {
169
167
  switch (node.length) {
@@ -188,14 +186,14 @@ const visit = ({ found, notFound }) => cmp => {
188
186
  switch (i3(v1)) {
189
187
  case 0: {
190
188
  return merge2
191
- (o => [...o, v1, n2])
189
+ (e => [...e, v1, n2])
192
190
  (r => [r, v1, n2])
193
191
  (f(n0))
194
192
  }
195
193
  case 1: { return found.branch3(init)(node) }
196
194
  default: {
197
195
  return merge2
198
- (o => [n0, v1, ...o])
196
+ (e => [n0, v1, ...e])
199
197
  (r => [n0, v1, r])
200
198
  (f(n2))
201
199
  }
@@ -339,7 +337,7 @@ module.exports = {
339
337
  * @type { <T>(cmp: Cmp<T>) => (node: Node<T>) => T|undefined }
340
338
  */
341
339
  getVisitor: cmp => node => {
342
- const result = visit(getVisitor)(cmp)(() => { throw '' })(node)
340
+ const result = visit(getVisitor)(cmp)(() => { throw 'getVisitor' })(node)
343
341
  if (result[0] === 'done') { return result[1] }
344
342
  return undefined
345
343
  },
@@ -43,7 +43,7 @@ const at = name => map => {
43
43
  }
44
44
 
45
45
  /** @type {(name: string) => <T>(value: T) => (map: Map<T>) => Map<T>} */
46
- const insert = name => value => map => {
46
+ const set = name => value => map => {
47
47
  /** @type {Entry<typeof value>} */
48
48
  const entry = [name, value]
49
49
  if (map === undefined) { return [entry] }
@@ -58,12 +58,12 @@ const insert = name => value => map => {
58
58
  const entries = map => map === undefined ? [] : values(map)
59
59
 
60
60
  /** @type {<T>(map: Map<T>) => (entry: Entry<T>) => Map<T>} */
61
- const insertOp = map => ([name, value]) => insert(name)(value)(map)
61
+ const setOp = map => ([name, value]) => set(name)(value)(map)
62
62
 
63
63
  /** @type {<T>(entries: seq.Sequence<Entry<T>>) => Map<T>} */
64
64
  const fromEntries = entries => {
65
65
  /** @typedef {typeof entries extends seq.Sequence<Entry<infer T>> ? T : never} T */
66
- return seq.reduce(insertOp)(/** @type {Map<T>} */(undefined))(entries)
66
+ return seq.reduce(setOp)(/** @type {Map<T>} */(undefined))(entries)
67
67
  }
68
68
 
69
69
  module.exports = {
@@ -72,8 +72,8 @@ module.exports = {
72
72
  /** @readonly */
73
73
  at,
74
74
  /** @readonly */
75
- insert,
76
- /** @readonlg */
75
+ set,
76
+ /** @readonly */
77
77
  entries,
78
78
  /** @readonly */
79
79
  fromEntries,
package/types/map/test.js CHANGED
@@ -1,26 +1,26 @@
1
- const { at, insert, empty, entries } = require('.')
2
- const list = require('../sequence')
1
+ const { at, set, empty, entries } = require('.')
2
+ const seq = require('../sequence')
3
3
 
4
4
  {
5
- let m = insert('a')(1)(undefined)
5
+ let m = set('a')(1)(undefined)
6
6
 
7
7
  if (at('a')(m) !== 1) { throw 'error' }
8
8
  if (at('b')(m) !== undefined) { throw 'error' }
9
9
 
10
- m = insert('b')(2)(m)
10
+ m = set('b')(2)(m)
11
11
 
12
12
  if (at('a')(m) !== 1) { throw 'error' }
13
13
  if (at('b')(m) !== 2) { throw 'error' }
14
14
  if (at('c')(m) !== undefined) { throw 'error' }
15
15
 
16
- m = insert('z')(3)(m)
16
+ m = set('z')(3)(m)
17
17
 
18
18
  if (at('a')(m) !== 1) { throw 'error' }
19
19
  if (at('b')(m) !== 2) { throw 'error' }
20
20
  if (at('z')(m) !== 3) { throw 'error' }
21
21
  if (at('')(m) !== undefined) { throw 'error' }
22
22
 
23
- m = insert('')(4)(m)
23
+ m = set('')(4)(m)
24
24
 
25
25
  if (at('a')(m) !== 1) { throw 'error' }
26
26
  if (at('b')(m) !== 2) { throw 'error' }
@@ -28,7 +28,7 @@ const list = require('../sequence')
28
28
  if (at('')(m) !== 4) { throw 'error' }
29
29
  if (at('Hello world!')(m) !== undefined) { throw 'error' }
30
30
 
31
- m = insert('Hello world!')(42)(m)
31
+ m = set('Hello world!')(42)(m)
32
32
 
33
33
  if (at('a')(m) !== 1) { throw 'error' }
34
34
  if (at('b')(m) !== 2) { throw 'error' }
@@ -41,12 +41,12 @@ const list = require('../sequence')
41
41
  }
42
42
 
43
43
  {
44
- let m = insert('x')(12)(undefined)
45
- m = insert('y')(44)(m)
44
+ let m = set('x')(12)(undefined)
45
+ m = set('y')(44)(m)
46
46
  if (at('x')(m) !== 12) { throw 'error' }
47
47
  if (at('y')(m) !== 44) { throw 'error' }
48
48
  if (at('a')(m) !== undefined) { throw 'error' }
49
- const e = list.toArray(entries(m))
49
+ const e = seq.toArray(entries(m))
50
50
  if (e.length !== 2) { throw 'error' }
51
51
  }
52
52
 
@@ -54,7 +54,7 @@ const list = require('../sequence')
54
54
  /** @type {import('.').Map<number>} */
55
55
  let m = empty
56
56
  for (let i = 0; i < 100_000; ++i) {
57
- m = insert((i * i).toString())(i)(m)
57
+ m = set((i * i).toString())(i)(m)
58
58
  /*
59
59
  console.log()
60
60
  console.log(`# ${i}`)