functionalscript 0.0.489 → 0.0.491

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.
@@ -16,4 +16,4 @@ jobs:
16
16
  - uses: denoland/setup-deno@v1
17
17
  with:
18
18
  deno-version: v1.x
19
- - run: deno run --allow-read --allow-env --allow-net ./dev/test.mjs
19
+ - run: deno run --allow-read --allow-env --allow-net --allow-hrtime ./dev/test.mjs
@@ -26,11 +26,17 @@ const { reset, fgGreen } = require('../../text/sgr/module.f.cjs')
26
26
  * @typedef {(v: string) => (state: T) => T} Log
27
27
  */
28
28
 
29
+ /**
30
+ * @template T
31
+ * @typedef {(state: T) => readonly[number, T]} PerformanceNow
32
+ */
33
+
29
34
  /**
30
35
  * @template T
31
36
  * @typedef {{
32
37
  * readonly moduleMap: ModuleMap,
33
38
  * readonly log: Log<T>,
39
+ * readonly performanceNow: PerformanceNow<T>,
34
40
  * readonly state: T,
35
41
  * }} Input
36
42
  */
@@ -38,49 +44,66 @@ const { reset, fgGreen } = require('../../text/sgr/module.f.cjs')
38
44
  /** @type {(s: string) => boolean} */
39
45
  const isTest = s => s.endsWith('test.f.cjs')
40
46
 
47
+ /**
48
+ * @template T
49
+ * @typedef {readonly[number, T]} State
50
+ */
51
+
41
52
  /** @type {<T>(input: Input<T>) => T} */
42
- const main = ({moduleMap, log, state}) => {
43
- /** @typedef {log extends Log<infer T> ? T : never} T */
44
- /** @type {(i: string) => (v: unknown) => (state: T) => T} */
45
- const test = i => v => state => {
53
+ const main = input => {
54
+ let { moduleMap, log, performanceNow, state } = input
55
+ /** @typedef {input extends Input<infer T> ? T : never} T */
56
+ /** @type {(i: string) => (v: unknown) => (state: State<T>) => State<T>} */
57
+ const test = i => v => ([time, state]) => {
46
58
  const next = test(`${i}| `)
47
59
  switch (typeof v) {
48
60
  case 'function': {
49
61
  if (v.length === 0) {
62
+ let b = 0;
63
+ [b, state] = performanceNow(state)
50
64
  const r = v()
51
- state = log(`${i}() ${fgGreen}ok${reset}`)(state)
52
- state = next(r)(state)
65
+ let e = 0;
66
+ [e, state] = performanceNow(state)
67
+ const delta = e - b
68
+ time += delta
69
+ state = log(`${i}() ${fgGreen}ok${reset}, ${delta} ms`)(state);
70
+ [time, state] = next(r)([time, state])
53
71
  }
54
72
  break
55
73
  }
56
74
  case 'object': {
57
- /** @type {(k: readonly[string|number, unknown]) => (state: T) => T} */
58
- const f = ([k, v]) => state => {
59
- state = log(`${i}${k}:`)(state)
60
- state = next(v)(state)
61
- return state
75
+ /** @type {(k: readonly[string|number, unknown]) => (state: State<T>) => State<T>} */
76
+ const f = ([k, v]) => ([time, state]) => {
77
+ state = log(`${i}${k}:`)(state);
78
+ [time, state] = next(v)([time, state])
79
+ return [time, state]
62
80
  }
63
- const foldF = fold(f)(state)
81
+ const foldF = fold(f)([time, state])
64
82
  if (v instanceof Array) {
65
- state = foldF(list.entries(v))
83
+ [time, state] = foldF(list.entries(v))
66
84
  } else if (v !== null) {
67
- state = foldF(Object.entries(v))
85
+ [time, state] = foldF(Object.entries(v))
68
86
  }
69
87
  break
70
88
  }
71
89
  }
72
- return state
90
+ return [time, state]
73
91
  }
74
92
  const next = test('| ')
75
- /** @type {(k: readonly[string, Module]) => (state: T) => T} */
76
- const f = ([k, v]) => state => {
93
+ /** @type {(k: readonly[string, Module]) => (fs: State<T>) => State<T>} */
94
+ const f = ([k, v]) => ([time, state]) => {
77
95
  if (isTest(k)) {
78
- state = log(`testing ${k}`)(state)
79
- state = next(v.exports)(state)
96
+ state = log(`testing ${k}`)(state);
97
+ [time, state] = next(v.exports)([time, state])
80
98
  }
81
- return state
99
+ return [time, state]
82
100
  }
83
- return fold(f)(state)(Object.entries(moduleMap))
101
+ /** @type {State<T>} */
102
+ const init = [0, state]
103
+ let time = 0;
104
+ [time, state] = fold(f)(init)(Object.entries(moduleMap))
105
+ state = log(`total ${time} ms`)(state);
106
+ return state
84
107
  }
85
108
 
86
109
  module.exports = main
package/dev/test.mjs CHANGED
@@ -1,20 +1,24 @@
1
1
  import { loadModuleMap } from './module.mjs'
2
2
 
3
+ /** @type {(s: string) => <T>(_: T) => T} */
4
+ const log = s => state => {
5
+ console.log(s)
6
+ return state
7
+ }
8
+
9
+ /** @type {<T>(_: T) => readonly[number, T]} */
10
+ const performanceNow = state => [performance.now(), state]
11
+
3
12
  // test runner.
4
13
  const main = async() => {
5
14
  const moduleMap = await loadModuleMap()
6
15
 
7
- /** @type {(s: string) => <T>(_: T) => T} */
8
- const log = s => state => {
9
- console.log(s)
10
- return state
11
- }
12
-
13
16
  /** @type {any} */
14
17
  const f = moduleMap['./dev/test/module.f.cjs'].exports
15
18
  f({
16
19
  moduleMap,
17
20
  log,
21
+ performanceNow,
18
22
  })
19
23
  }
20
24
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "functionalscript",
3
- "version": "0.0.489",
3
+ "version": "0.0.491",
4
4
  "description": "FunctionalScript is a functional subset of JavaScript",
5
5
  "main": "module.f.cjs",
6
6
  "scripts": {
@@ -30,7 +30,7 @@
30
30
  },
31
31
  "homepage": "https://github.com/functionalscript/functionalscript#readme",
32
32
  "devDependencies": {
33
- "@types/node": "^18.11.9",
34
- "typescript": "^4.9.3"
33
+ "@types/node": "^18.11.15",
34
+ "typescript": "^4.9.4"
35
35
  }
36
36
  }