functionalscript 0.0.274 → 0.0.278
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/README.md +1 -1
- package/commonjs/build/index.js +27 -3
- package/package.json +1 -1
- package/test.js +1 -0
- package/types/array/index.js +17 -22
- package/types/array/test.js +94 -0
package/README.md
CHANGED
|
@@ -161,7 +161,7 @@ Expressions could fall under these categories:
|
|
|
161
161
|
- Relations Operators: `in`, `instanceof`.
|
|
162
162
|
- Member Operators: `.`, `[]`.
|
|
163
163
|
|
|
164
|
-
Note: the `.` member operator has prohibitted property names, such as `constructor` and `push`. To access such properties, it's recommeded to use the
|
|
164
|
+
Note: the `.` member operator has prohibitted property names, such as `constructor` and `push`. To access such properties, it's recommeded to use the [Object.getOwnPropertyDescriptor](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/getOwnPropertyDescriptor) function.
|
|
165
165
|
|
|
166
166
|
## 4. Arrow Functions
|
|
167
167
|
|
package/commonjs/build/index.js
CHANGED
|
@@ -4,7 +4,7 @@ const function_ = require('../module/function')
|
|
|
4
4
|
const { todo } = require('../../dev')
|
|
5
5
|
const map = require('../../types/map')
|
|
6
6
|
const object = require('../../types/object')
|
|
7
|
-
const
|
|
7
|
+
const path = require('../path')
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* @template M
|
|
@@ -47,8 +47,32 @@ const getOrBuild = packageGet => moduleMapInterface => compile => moduleId => {
|
|
|
47
47
|
}
|
|
48
48
|
|
|
49
49
|
/** @type {function_.Require<readonly[M, map.Map<string>]>} */
|
|
50
|
-
const require_ =
|
|
51
|
-
|
|
50
|
+
const require_ = pathStr => prior => {
|
|
51
|
+
const pathResult = path.parseAndFind(packageGet)(moduleId.packageId)(moduleIdStr)(pathStr)
|
|
52
|
+
if (pathResult === undefined) { return [['error', `file not found: '${pathStr}'`], prior] }
|
|
53
|
+
const mId = { packageId: pathResult.package, path: pathResult.file.split('/') }
|
|
54
|
+
const [state, newMap] = getOrBuild
|
|
55
|
+
(packageGet)
|
|
56
|
+
(moduleMapInterface)
|
|
57
|
+
(compile)
|
|
58
|
+
(mId)
|
|
59
|
+
(prior[0])
|
|
60
|
+
switch (state[0]) {
|
|
61
|
+
case 'ok': {
|
|
62
|
+
const newRequireMap = map.set(pathStr)(module_.idToString(mId))(prior[1])
|
|
63
|
+
return [
|
|
64
|
+
['ok', state[1].exports],
|
|
65
|
+
[newMap, newRequireMap]
|
|
66
|
+
]
|
|
67
|
+
}
|
|
68
|
+
case 'building': {
|
|
69
|
+
return todo()
|
|
70
|
+
}
|
|
71
|
+
// 'ok'
|
|
72
|
+
default: {
|
|
73
|
+
return todo()
|
|
74
|
+
}
|
|
75
|
+
}
|
|
52
76
|
}
|
|
53
77
|
|
|
54
78
|
return moduleMapFirst => {
|
package/package.json
CHANGED
package/test.js
CHANGED
package/types/array/index.js
CHANGED
|
@@ -3,53 +3,48 @@ const seq = require('../list')
|
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* @template T
|
|
6
|
-
* @typedef {readonly
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* @template T
|
|
11
|
-
* @typedef {readonly [T]} Array1
|
|
6
|
+
* @typedef {readonly[T]} Array1
|
|
12
7
|
*/
|
|
13
8
|
|
|
14
9
|
/** @typedef {0} Index1 */
|
|
15
10
|
|
|
16
11
|
/**
|
|
17
12
|
* @template T
|
|
18
|
-
* @typedef {readonly
|
|
13
|
+
* @typedef {readonly[T, T]} Array2
|
|
19
14
|
*/
|
|
20
15
|
|
|
21
16
|
/**
|
|
22
17
|
* @template T0
|
|
23
18
|
* @template T1
|
|
24
|
-
* @typedef {readonly
|
|
19
|
+
* @typedef {readonly[T0, T1]} Tuple2
|
|
25
20
|
*/
|
|
26
21
|
|
|
27
22
|
/** @typedef {0|1} Index2 */
|
|
28
23
|
|
|
29
24
|
/**
|
|
30
25
|
* @template T
|
|
31
|
-
* @typedef {readonly
|
|
26
|
+
* @typedef {readonly[T, T, T]} Array3
|
|
32
27
|
*/
|
|
33
28
|
|
|
34
29
|
/**
|
|
35
30
|
* @template T0
|
|
36
31
|
* @template T1
|
|
37
32
|
* @template T2
|
|
38
|
-
* @typedef {readonly
|
|
33
|
+
* @typedef {readonly[T0, T1, T2]} Tuple3
|
|
39
34
|
*/
|
|
40
35
|
|
|
41
36
|
/** @typedef {0|1|2} Index3 */
|
|
42
37
|
|
|
43
38
|
/**
|
|
44
39
|
* @template T
|
|
45
|
-
* @typedef {readonly
|
|
40
|
+
* @typedef {readonly[T, T, T, T]} Array4
|
|
46
41
|
*/
|
|
47
42
|
|
|
48
43
|
/** @typedef {0|1|2|3} Index4 */
|
|
49
44
|
|
|
50
45
|
/**
|
|
51
46
|
* @template T
|
|
52
|
-
* @typedef {readonly
|
|
47
|
+
* @typedef {readonly[T, T, T, T, T]} Array5
|
|
53
48
|
*/
|
|
54
49
|
|
|
55
50
|
/**
|
|
@@ -59,40 +54,40 @@ const seq = require('../list')
|
|
|
59
54
|
|
|
60
55
|
/** @typedef {0|1|2|3|4} Index5 */
|
|
61
56
|
|
|
62
|
-
/** @type {<T>(_:
|
|
57
|
+
/** @type {<T>(_: readonly T[]) => readonly T[]} */
|
|
63
58
|
const uncheckTail = a => a.slice(1)
|
|
64
59
|
|
|
65
|
-
/** @type {<T>(_:
|
|
60
|
+
/** @type {<T>(_: readonly T[]) => readonly T[]} */
|
|
66
61
|
const uncheckHead = a => a.slice(0, -1)
|
|
67
62
|
|
|
68
|
-
/** @type {<T>(_:
|
|
63
|
+
/** @type {<T>(_: readonly T[]) => T|undefined} */
|
|
69
64
|
const first = a => a[0]
|
|
70
65
|
|
|
71
|
-
/** @type {<T>(_:
|
|
66
|
+
/** @type {<T>(_: readonly T[]) => T|undefined} */
|
|
72
67
|
const last = a => a[a.length - 1]
|
|
73
68
|
|
|
74
|
-
/** @type {<T>(_:
|
|
69
|
+
/** @type {<T>(_: readonly T[]) => readonly T[] | undefined} */
|
|
75
70
|
const tail = a => a.length === 0 ? undefined : uncheckTail(a)
|
|
76
71
|
|
|
77
|
-
/** @type {<T>(_:
|
|
72
|
+
/** @type {<T>(_: readonly T[]) => readonly[T, readonly T[]]|undefined} */
|
|
78
73
|
const splitFirst = a => {
|
|
79
74
|
/** @typedef {typeof a[0]} T*/
|
|
80
|
-
/** @type {(_: T) => readonly
|
|
75
|
+
/** @type {(_: T) => readonly[T, readonly T[]]} */
|
|
81
76
|
const split = first => [first, uncheckTail(a)]
|
|
82
77
|
return option.map(split)(a[0])
|
|
83
78
|
}
|
|
84
79
|
|
|
85
|
-
/** @type {<T>(_:
|
|
80
|
+
/** @type {<T>(_: readonly T[]) => readonly T[]|undefined} */
|
|
86
81
|
const head = a => a.length === 0 ? undefined : uncheckHead(a)
|
|
87
82
|
|
|
88
|
-
/** @type {<T>(_:
|
|
83
|
+
/** @type {<T>(_: readonly T[]) => readonly[readonly T[], T]|undefined} */
|
|
89
84
|
const splitLast = a => {
|
|
90
85
|
const lastA = last(a)
|
|
91
86
|
if (lastA === undefined) { return undefined }
|
|
92
87
|
return [uncheckHead(a), lastA]
|
|
93
88
|
}
|
|
94
89
|
|
|
95
|
-
/** @type {(index: number) => <T>(a:
|
|
90
|
+
/** @type {(index: number) => <T>(a: readonly T[]) => readonly[T]|undefined} */
|
|
96
91
|
const at = index => a => index < a.length ? [a[index]] : undefined
|
|
97
92
|
|
|
98
93
|
module.exports = {
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
const _ = require('.')
|
|
2
|
+
const json = require('../../json')
|
|
3
|
+
const { sort } = require('../object')
|
|
4
|
+
|
|
5
|
+
/** @type {(a: readonly json.Unknown[]) => string} */
|
|
6
|
+
const stringify = a => json.stringify(sort)(a)
|
|
7
|
+
|
|
8
|
+
{
|
|
9
|
+
const result = stringify([1, 20, 300])
|
|
10
|
+
if (result !== '[1,20,300]') { throw result }
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
{
|
|
14
|
+
const result = _.at(2)([1, 20, 300])
|
|
15
|
+
if (result === undefined) {throw result}
|
|
16
|
+
if (result[0] !== 300) { throw result }
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
{
|
|
20
|
+
const result = _.at(3)([1, 20, 300])
|
|
21
|
+
if (result !== undefined) {throw result}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
{
|
|
25
|
+
const result = _.first([1, 20, 300])
|
|
26
|
+
if (result !== 1) { throw result }
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
{
|
|
30
|
+
const result = _.first([])
|
|
31
|
+
if (result !== undefined) {throw result}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
{
|
|
35
|
+
const result = _.last([1, 20, 300])
|
|
36
|
+
if (result !== 300) { throw result }
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
{
|
|
40
|
+
const result = _.last([])
|
|
41
|
+
if (result !== undefined) {throw result}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
{
|
|
45
|
+
const result = _.head([1, 20, 300])
|
|
46
|
+
if (result === undefined) {throw result}
|
|
47
|
+
const str = stringify(result)
|
|
48
|
+
if (str !== '[1,20]') { throw str }
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
{
|
|
52
|
+
const result = _.head([])
|
|
53
|
+
if (result !== undefined) {throw result}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
{
|
|
57
|
+
const result = _.tail([1, 20, 300])
|
|
58
|
+
if (result === undefined) {throw result}
|
|
59
|
+
const str = stringify(result)
|
|
60
|
+
if (str !== '[20,300]') { throw str }
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
{
|
|
64
|
+
const result = _.tail([])
|
|
65
|
+
if (result !== undefined) {throw result}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
{
|
|
69
|
+
const result = _.splitFirst([1, 20, 300])
|
|
70
|
+
if (result === undefined) {throw result}
|
|
71
|
+
const str = stringify(result)
|
|
72
|
+
if (str !== '[1,[20,300]]') { throw str }
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
{
|
|
76
|
+
const result = _.splitFirst([])
|
|
77
|
+
if (result !== undefined) {throw result}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
{
|
|
81
|
+
const result = _.splitLast([1, 20, 300])
|
|
82
|
+
if (result === undefined) {throw result}
|
|
83
|
+
const str = stringify(result)
|
|
84
|
+
if (str !== '[[1,20],300]') { throw str }
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
{
|
|
88
|
+
const result = _.splitLast([])
|
|
89
|
+
if (result !== undefined) {throw result}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
module.exports = {
|
|
93
|
+
|
|
94
|
+
}
|