functionalscript 0.0.228 → 0.0.232
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/commonjs/index.js +11 -0
- package/commonjs/path/index.js +64 -0
- package/commonjs/path/test.js +47 -0
- package/commonjs/run/index.js +17 -0
- package/io/commonjs/index.js +34 -0
- package/io/commonjs/test.js +72 -0
- package/json/index.js +22 -26
- package/json/test.js +9 -9
- package/package.json +23 -23
- package/test.js +4 -6
- package/{sequence → types}/array/index.js +2 -2
- package/{btree → types/btree}/README.md +0 -0
- package/{btree → types/btree}/index.js +6 -6
- package/{btree → types/btree}/test.js +1 -1
- package/{cmp → types/function/compare}/index.js +6 -6
- package/{function → types/function}/index.js +0 -0
- package/{function → types/function}/operator/index.js +15 -0
- package/{map → types/map}/index.js +3 -3
- package/{map → types/map}/test.js +0 -0
- package/{object → types/object}/index.js +1 -2
- package/{object → types/object}/test.js +0 -0
- package/{option → types/option}/index.js +0 -0
- package/types/result/index.js +28 -0
- package/{sequence → types/sequence}/README.md +0 -0
- package/{sequence → types/sequence}/index.js +117 -60
- package/{sequence → types/sequence}/test.js +148 -11
- package/version.js +2 -2
- package/module-manager/README.md +0 -35
- package/module-manager/index.js +0 -110
- package/module-manager/node/index.js +0 -18
- package/module-manager/node/test.js +0 -75
- package/module-manager/test.js +0 -120
- package/result/index.js +0 -17
- package/sequence/asyncIterable/index.js +0 -111
- package/sequence/asyncIterable/test.js +0 -24
- package/sequence/iterable/index.js +0 -109
- package/sequence/iterable/test.js +0 -51
- package/sequence/operator/index.js +0 -92
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
const seq = require("../../types/sequence")
|
|
2
|
+
const option = require("../../types/option")
|
|
3
|
+
const { compose } = require("../../types/function")
|
|
4
|
+
|
|
5
|
+
/** @typedef {readonly string[]} Items */
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @typedef {{
|
|
9
|
+
* readonly external: boolean
|
|
10
|
+
* readonly dir: boolean
|
|
11
|
+
* readonly items: Items
|
|
12
|
+
* }} Path
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
/** @type {(path: string) => seq.Sequence<string>} */
|
|
16
|
+
const split = path => path.split('/')
|
|
17
|
+
|
|
18
|
+
/** @type {(s: undefined|seq.Sequence<string>) => (items: string) => undefined|seq.Sequence<string>} */
|
|
19
|
+
const normItemsOp = prior => item => {
|
|
20
|
+
if (prior === undefined) { return undefined }
|
|
21
|
+
switch (item) {
|
|
22
|
+
case '': case '.': { return prior }
|
|
23
|
+
case '..': {
|
|
24
|
+
const result = seq.next(prior)
|
|
25
|
+
if (result === undefined) { return undefined }
|
|
26
|
+
return result.tail
|
|
27
|
+
}
|
|
28
|
+
default: {
|
|
29
|
+
return seq.sequence(item)(prior)
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** @type {(items: seq.Sequence<string>) => seq.Sequence<string>|undefined} */
|
|
35
|
+
const normItems = compose(seq.reduce(normItemsOp)([]))(option.map(seq.reverse))
|
|
36
|
+
|
|
37
|
+
/** @type {(local: string) => (path: string) => Path|undefined} */
|
|
38
|
+
const parse = local => {
|
|
39
|
+
/** @type {(path: string) => readonly[boolean, seq.Sequence<string>]} */
|
|
40
|
+
const fSeq = path => {
|
|
41
|
+
const pathSeq = split(path)
|
|
42
|
+
switch (seq.first(undefined)(pathSeq)) {
|
|
43
|
+
case '.': case '..': { return [false, seq.flat([split(local), pathSeq])] }
|
|
44
|
+
default: { return [true, pathSeq] }
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
/** @type {(path: string) => Path|undefined} */
|
|
48
|
+
const f = path => {
|
|
49
|
+
const [external, items] = fSeq(path)
|
|
50
|
+
const n = normItems(items)
|
|
51
|
+
if (n === undefined) { return undefined }
|
|
52
|
+
return {
|
|
53
|
+
external,
|
|
54
|
+
dir: path[path.length - 1] === '/',
|
|
55
|
+
items: seq.toArray(n)
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return f
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
module.exports = {
|
|
62
|
+
/** @readonly */
|
|
63
|
+
parse,
|
|
64
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
const _ = require('.')
|
|
2
|
+
const json = require('../../json')
|
|
3
|
+
const { identity, compose } = require('../../types/function')
|
|
4
|
+
const seq = require('../../types/sequence')
|
|
5
|
+
|
|
6
|
+
const stringify = json.stringify(identity)
|
|
7
|
+
|
|
8
|
+
{
|
|
9
|
+
const result = _.parse('')('./a')
|
|
10
|
+
if (result === undefined) { throw result }
|
|
11
|
+
if (stringify(result) !== '{"external":false,"dir":false,"items":["a"]}') { throw result }
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
{
|
|
15
|
+
const result = _.parse('')('./a/')
|
|
16
|
+
if (result === undefined) { throw result }
|
|
17
|
+
if (stringify(result) !== '{"external":false,"dir":true,"items":["a"]}') { throw result }
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
{
|
|
21
|
+
const result = _.parse('')('..')
|
|
22
|
+
if (result !== undefined) { throw result }
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
{
|
|
26
|
+
const result = _.parse('a')('')
|
|
27
|
+
if (result === undefined) { throw result }
|
|
28
|
+
if (stringify(result) !== '{"external":true,"dir":false,"items":[]}') { throw result }
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
{
|
|
32
|
+
const result = _.parse('')('./a/b/.././c')
|
|
33
|
+
if (result === undefined) { throw result }
|
|
34
|
+
if (stringify(result) !== '{"external":false,"dir":false,"items":["a","c"]}') { throw result }
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
{
|
|
38
|
+
const result = _.parse('x/r')('./a/b/.././c')
|
|
39
|
+
if (result === undefined) { throw result }
|
|
40
|
+
if (stringify(result) !== '{"external":false,"dir":false,"items":["x","r","a","c"]}') { throw result }
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
{
|
|
44
|
+
const result = _.parse('a')('a/b/.././c')
|
|
45
|
+
if (result === undefined) { throw result }
|
|
46
|
+
if (stringify(result) !== '{"external":true,"dir":false,"items":["a","c"]}') { throw result }
|
|
47
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
const result = require('../../types/result')
|
|
2
|
+
|
|
3
|
+
/** @typedef {<T>(req: Require<T>) => (prior: T) => ModuleResult<T>} Module*/
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @template T
|
|
7
|
+
* @typedef {readonly[result.Result<unknown, unknown>, T]} ModuleResult
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @template T
|
|
12
|
+
* @typedef {(prior: T) => (path: string) => ModuleResult<T>} Require
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
/** @typedef {(source: string) => result.Result<Module, unknown>} Compile */
|
|
16
|
+
|
|
17
|
+
module.exports = {}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
const { ok, error } = require('../../types/result')
|
|
2
|
+
const run = require('../../commonjs/run')
|
|
3
|
+
|
|
4
|
+
/** @type {(f: Function) => run.Module} */
|
|
5
|
+
const runModule = f => req => info => {
|
|
6
|
+
/** @type {(path: string) => unknown} */
|
|
7
|
+
const mutableRequire = path => {
|
|
8
|
+
const [result, newInfo] = req(info)(path)
|
|
9
|
+
info = newInfo
|
|
10
|
+
if (result[0] === 'error') { throw result[1] }
|
|
11
|
+
return result[1]
|
|
12
|
+
}
|
|
13
|
+
const mutableModule = { exports: {} }
|
|
14
|
+
try {
|
|
15
|
+
f(mutableModule, mutableRequire)
|
|
16
|
+
} catch (e) {
|
|
17
|
+
return [error(e), info]
|
|
18
|
+
}
|
|
19
|
+
return [ok(mutableModule.exports), info]
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** @type {run.Compile} */
|
|
23
|
+
const compile = source => {
|
|
24
|
+
try {
|
|
25
|
+
return ok(runModule(Function('module', 'require', `"use strict";${source}`)))
|
|
26
|
+
} catch (e) {
|
|
27
|
+
return error(e)
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
module.exports = {
|
|
32
|
+
/** @readonly */
|
|
33
|
+
compile,
|
|
34
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
const _ = require('.')
|
|
2
|
+
const run = require('../../commonjs/run')
|
|
3
|
+
|
|
4
|
+
// ok:
|
|
5
|
+
{
|
|
6
|
+
const source = 'module.exports = "Hello world!"'
|
|
7
|
+
const m = _.compile(source)
|
|
8
|
+
if (m[0] !== 'ok') { throw m }
|
|
9
|
+
const [result] = m[1](() => { throw 0 })(undefined)
|
|
10
|
+
if (result[0] !== 'ok') { throw result }
|
|
11
|
+
if (result[1] !== 'Hello world!') { throw result }
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// compilation error:
|
|
15
|
+
{
|
|
16
|
+
const source = '+'
|
|
17
|
+
const m = _.compile(source)
|
|
18
|
+
if (m[0] !== 'error') { throw m }
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// compilation error with "use strict;":
|
|
22
|
+
{
|
|
23
|
+
const source = 'const x = 04'
|
|
24
|
+
const m = _.compile(source)
|
|
25
|
+
if (m[0] !== 'error') { throw m }
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// runtime error:
|
|
29
|
+
{
|
|
30
|
+
const source = 'a = 5'
|
|
31
|
+
const m = _.compile(source)
|
|
32
|
+
if (m[0] !== 'ok') { throw m }
|
|
33
|
+
const [result] = m[1](() => { throw 0 })(undefined)
|
|
34
|
+
if (result[0] !== 'error') { throw result }
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
//
|
|
38
|
+
{
|
|
39
|
+
const depSource = 'module.exports = 137'
|
|
40
|
+
const d = _.compile(depSource)
|
|
41
|
+
if (d[0] !== 'ok') { throw d }
|
|
42
|
+
|
|
43
|
+
/** @type {run.Require<number>} */
|
|
44
|
+
const req = prior => path => {
|
|
45
|
+
if (path !== 'm') { throw path }
|
|
46
|
+
return d[1](req)(prior + 1)
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
let info = 0
|
|
50
|
+
{
|
|
51
|
+
const source = 'module.exports = require("m") + 42'
|
|
52
|
+
const m = _.compile(source)
|
|
53
|
+
if (m[0] !== 'ok') { throw m }
|
|
54
|
+
|
|
55
|
+
const [result, newInfo] = m[1](req)(info)
|
|
56
|
+
if (result[0] !== 'ok') { throw result }
|
|
57
|
+
if (result[1] !== 179) { throw result }
|
|
58
|
+
info = newInfo
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
{
|
|
62
|
+
const source = 'module.exports = require("x") + 42'
|
|
63
|
+
const m = _.compile(source)
|
|
64
|
+
if (m[0] !== 'ok') { throw m }
|
|
65
|
+
|
|
66
|
+
const [result, infox] = m[1](req)(info)
|
|
67
|
+
if (result[0] !== 'error') { throw result }
|
|
68
|
+
if (infox !== 1) { throw info }
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
module.exports = {}
|
package/json/index.js
CHANGED
|
@@ -1,22 +1,20 @@
|
|
|
1
|
-
const seq = require('../sequence')
|
|
2
|
-
const
|
|
3
|
-
const
|
|
4
|
-
const array = require('../sequence/array')
|
|
5
|
-
const { compose } = require('../function')
|
|
1
|
+
const seq = require('../types/sequence')
|
|
2
|
+
const object = require('../types/object')
|
|
3
|
+
const array = require('../types/array')
|
|
6
4
|
|
|
7
5
|
/**
|
|
8
6
|
* @typedef {{
|
|
9
|
-
* readonly [k in string]:
|
|
7
|
+
* readonly [k in string]: Unknown
|
|
10
8
|
* }} Object
|
|
11
9
|
*/
|
|
12
10
|
|
|
13
|
-
/** @typedef {readonly
|
|
11
|
+
/** @typedef {readonly Unknown[]} Array */
|
|
14
12
|
|
|
15
|
-
/** @typedef {Object|boolean|string|number|null|Array}
|
|
13
|
+
/** @typedef {Object|boolean|string|number|null|Array} Unknown */
|
|
16
14
|
|
|
17
|
-
/** @type {(value:
|
|
18
|
-
const
|
|
19
|
-
/** @type {(path: seq.Sequence<string>) => (src:
|
|
15
|
+
/** @type {(value: Unknown) => (path: seq.Sequence<string>) => (src: Unknown|undefined) => Unknown} */
|
|
16
|
+
const setProperty = value => {
|
|
17
|
+
/** @type {(path: seq.Sequence<string>) => (src: Unknown|undefined) => Unknown} */
|
|
20
18
|
const f = path => src => {
|
|
21
19
|
const result = seq.next(path)
|
|
22
20
|
if (result === undefined) { return value }
|
|
@@ -45,11 +43,8 @@ const boolSerialize = value => value ? trueSerialize : falseSerialize
|
|
|
45
43
|
const colon = [':']
|
|
46
44
|
const comma = [',']
|
|
47
45
|
|
|
48
|
-
/** @type {op.Scan<seq.Sequence<string>, seq.Sequence<string>>} */
|
|
49
|
-
const commaValue = a => [seq.concat(comma, a), commaValue]
|
|
50
|
-
|
|
51
46
|
/** @type {seq.FoldOperator<seq.Sequence<string>>} */
|
|
52
|
-
const joinOp = a => b => seq.
|
|
47
|
+
const joinOp = a => b => seq.flat([a, comma, b])
|
|
53
48
|
|
|
54
49
|
/** @type {(input: seq.Sequence<seq.Sequence<string>>) => seq.Sequence<string>} */
|
|
55
50
|
const join = seq.fold(joinOp)([])
|
|
@@ -58,26 +53,27 @@ const join = seq.fold(joinOp)([])
|
|
|
58
53
|
const list = open => close => {
|
|
59
54
|
const seqOpen = [open]
|
|
60
55
|
const seqClose = [close]
|
|
61
|
-
return input => seq.
|
|
56
|
+
return input => seq.flat([seqOpen, join(input), seqClose])
|
|
62
57
|
}
|
|
63
58
|
|
|
64
59
|
const objectList = list('{')('}')
|
|
65
60
|
|
|
66
61
|
const arrayList = list('[')(']')
|
|
67
62
|
|
|
68
|
-
/** @typedef {object.Entry<
|
|
63
|
+
/** @typedef {object.Entry<Unknown>} Entry*/
|
|
69
64
|
|
|
70
65
|
/** @typedef {(seq.Sequence<Entry>)} Entries */
|
|
71
66
|
|
|
72
67
|
/** @typedef {(entries: Entries) => Entries} MapEntries */
|
|
73
68
|
|
|
74
|
-
/** @type {(mapEntries: MapEntries) => (value:
|
|
69
|
+
/** @type {(mapEntries: MapEntries) => (value: Unknown) => seq.Sequence<string>} */
|
|
75
70
|
const serialize = sort => {
|
|
76
|
-
/** @type {(kv: readonly[string,
|
|
77
|
-
const propertySerialize = ([k, v]) => seq.
|
|
71
|
+
/** @type {(kv: readonly[string, Unknown]) => seq.Sequence<string>} */
|
|
72
|
+
const propertySerialize = ([k, v]) => seq.flat([
|
|
78
73
|
stringSerialize(k),
|
|
79
74
|
colon,
|
|
80
|
-
f(v)
|
|
75
|
+
f(v)
|
|
76
|
+
])
|
|
81
77
|
/** @type {(object: Object) => seq.Sequence<string>} */
|
|
82
78
|
const objectSerialize = input => {
|
|
83
79
|
const entries = Object.entries(input)
|
|
@@ -91,7 +87,7 @@ const serialize = sort => {
|
|
|
91
87
|
const serializedEntries = seq.map(f)(input)
|
|
92
88
|
return arrayList(serializedEntries)
|
|
93
89
|
}
|
|
94
|
-
/** @type {(value:
|
|
90
|
+
/** @type {(value: Unknown) => seq.Sequence < string >} */
|
|
95
91
|
const f = value => {
|
|
96
92
|
switch (typeof value) {
|
|
97
93
|
case 'boolean': { return boolSerialize(value) }
|
|
@@ -110,22 +106,22 @@ const serialize = sort => {
|
|
|
110
106
|
/**
|
|
111
107
|
* A version of `JSON.stringify` with an alphabeticly ordered `keys`.
|
|
112
108
|
*
|
|
113
|
-
* The standard `JSON.stringify` rules
|
|
109
|
+
* The standard `JSON.stringify` rules determined by
|
|
114
110
|
* https://262.ecma-international.org/6.0/#sec-ordinary-object-internal-methods-and-internal-slots-ownpropertykeys
|
|
115
111
|
*
|
|
116
|
-
* @type {(mapEntries: MapEntries) => (value:
|
|
112
|
+
* @type {(mapEntries: MapEntries) => (value: Unknown) => string}
|
|
117
113
|
*/
|
|
118
114
|
const stringify = sort => value => {
|
|
119
115
|
const _s = serialize(sort)(value)
|
|
120
116
|
return seq.join('')(_s)
|
|
121
117
|
}
|
|
122
118
|
|
|
123
|
-
/** @type {(value: string) =>
|
|
119
|
+
/** @type {(value: string) => Unknown} */
|
|
124
120
|
const parse = value => JSON.parse(value)
|
|
125
121
|
|
|
126
122
|
module.exports = {
|
|
127
123
|
/** @readonly */
|
|
128
|
-
|
|
124
|
+
setProperty,
|
|
129
125
|
/** @readonly */
|
|
130
126
|
stringify,
|
|
131
127
|
/** @readonly */
|
package/json/test.js
CHANGED
|
@@ -1,40 +1,40 @@
|
|
|
1
1
|
const json = require('.')
|
|
2
|
-
const { sort } = require('../object')
|
|
3
|
-
const { identity } = require('../function')
|
|
2
|
+
const { sort } = require('../types/object')
|
|
3
|
+
const { identity } = require('../types/function')
|
|
4
4
|
|
|
5
|
-
if (json.
|
|
5
|
+
if (json.setProperty("Hello")([])({}) !== "Hello") { throw 'error' }
|
|
6
6
|
|
|
7
7
|
{
|
|
8
|
-
const r = json.
|
|
8
|
+
const r = json.setProperty("Hello")(['a'])({})
|
|
9
9
|
const x = json.stringify(sort)(r)
|
|
10
10
|
if (x !== '{"a":"Hello"}') { throw x }
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
{
|
|
14
|
-
const x = json.stringify(identity)(json.
|
|
14
|
+
const x = json.stringify(identity)(json.setProperty("Hello")(['a'])({}))
|
|
15
15
|
if (x !== '{"a":"Hello"}') { throw x }
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
{
|
|
19
|
-
const x = json.stringify(sort)(json.
|
|
19
|
+
const x = json.stringify(sort)(json.setProperty("Hello")(['a'])({c:[],b:12}))
|
|
20
20
|
if (x !== '{"a":"Hello","b":12,"c":[]}') { throw x }
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
{
|
|
24
|
-
const x = json.stringify(identity)(json.
|
|
24
|
+
const x = json.stringify(identity)(json.setProperty("Hello")(['a'])({ c: [], b: 12 }))
|
|
25
25
|
if (x !== '{"c":[],"b":12,"a":"Hello"}') { throw x }
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
{
|
|
29
29
|
const _0 = { a: { y: [24] }, c: [], b: 12 }
|
|
30
|
-
const _1 = json.
|
|
30
|
+
const _1 = json.setProperty("Hello")(['a', 'x'])(_0)
|
|
31
31
|
const _2 = json.stringify(sort)(_1)
|
|
32
32
|
if (_2 !== '{"a":{"x":"Hello","y":[24]},"b":12,"c":[]}') { throw _2 }
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
{
|
|
36
36
|
const _0 = { a: { y: [24] }, c: [], b: 12 }
|
|
37
|
-
const _1 = json.
|
|
37
|
+
const _1 = json.setProperty("Hello")(['a', 'x'])(_0)
|
|
38
38
|
const _2 = json.stringify(identity)(_1)
|
|
39
39
|
if (_2 !== '{"a":{"y":[24],"x":"Hello"},"c":[],"b":12}') { throw _2 }
|
|
40
40
|
}
|
package/package.json
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
2
|
+
"name": "functionalscript",
|
|
3
|
+
"version": "0.0.232",
|
|
4
|
+
"description": "FunctionalScript is a functional subset of JavaScript",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"tsc": "tsc",
|
|
8
|
+
"test": "tsc && npm run test-only",
|
|
9
|
+
"test-only": "node --trace-uncaught ./test"
|
|
10
|
+
},
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "git+https://github.com/functionalscript/functionalscript.git"
|
|
14
|
+
},
|
|
15
|
+
"author": "Natfoam",
|
|
16
|
+
"license": "Apache-2.0",
|
|
17
|
+
"bugs": {
|
|
18
|
+
"url": "https://github.com/functionalscript/functionalscript/issues"
|
|
19
|
+
},
|
|
20
|
+
"homepage": "https://github.com/functionalscript/functionalscript#readme",
|
|
21
|
+
"devDependencies": {
|
|
22
|
+
"@types/node": "^16.11.11",
|
|
23
|
+
"typescript": "^4.5.2"
|
|
24
|
+
}
|
|
25
25
|
}
|
package/test.js
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
const i = require('./')
|
|
2
2
|
|
|
3
|
-
require('./sequence/test')
|
|
4
|
-
require('./btree/test')
|
|
5
|
-
require('./sequence/iterable/test')
|
|
6
|
-
require('./sequence/asyncIterable/test')
|
|
7
|
-
require('./module-manager/test')
|
|
3
|
+
require('./types/sequence/test')
|
|
4
|
+
require('./types/btree/test')
|
|
8
5
|
require('./json/test')
|
|
9
|
-
require('./object/test')
|
|
6
|
+
require('./types/object/test')
|
|
7
|
+
require('./io/commonjs/test')
|
|
10
8
|
|
|
11
9
|
/** @type {() => never} */
|
|
12
10
|
const assert = () => { throw 'assert' }
|
|
File without changes
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const cmp = require('../
|
|
1
|
+
const cmp = require('../function/compare')
|
|
2
2
|
const { index3, index5 } = cmp
|
|
3
3
|
const seq = require('../sequence')
|
|
4
4
|
|
|
@@ -9,7 +9,7 @@ const seq = require('../sequence')
|
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* @template T
|
|
12
|
-
* @typedef {cmp.
|
|
12
|
+
* @typedef {cmp.Compare<T>} Cmp
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
15
|
/**
|
|
@@ -311,20 +311,20 @@ const values = node => () => {
|
|
|
311
311
|
switch (node.length) {
|
|
312
312
|
case 1: case 2: { return node }
|
|
313
313
|
case 3: {
|
|
314
|
-
return seq.
|
|
314
|
+
return seq.flat([
|
|
315
315
|
values(node[0]),
|
|
316
316
|
[node[1]],
|
|
317
317
|
values(node[2])
|
|
318
|
-
)
|
|
318
|
+
])
|
|
319
319
|
}
|
|
320
320
|
default: {
|
|
321
|
-
return seq.
|
|
321
|
+
return seq.flat([
|
|
322
322
|
values(node[0]),
|
|
323
323
|
[node[1]],
|
|
324
324
|
values(node[2]),
|
|
325
325
|
[node[3]],
|
|
326
326
|
values(node[4])
|
|
327
|
-
)
|
|
327
|
+
])
|
|
328
328
|
}
|
|
329
329
|
}
|
|
330
330
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const btree = require('.')
|
|
2
2
|
const { setVisitor, values } = btree
|
|
3
|
-
const { cmp } = require('../
|
|
3
|
+
const { cmp } = require('../function/compare')
|
|
4
4
|
const list = require('../sequence')
|
|
5
5
|
|
|
6
6
|
/** @type {(node: btree.Node<string>) => (value: string) => btree.Node<string>} */
|
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
/** @typedef {import('
|
|
2
|
-
/** @typedef {import('
|
|
1
|
+
/** @typedef {import('../../array').Index3} Index3 */
|
|
2
|
+
/** @typedef {import('../../array').Index5} Index5 */
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* @template T
|
|
6
|
-
* @typedef {import('
|
|
6
|
+
* @typedef {import('../../array').Array2<T>} Array2
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
/** @typedef {-1|0|1} Sign */
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* @template T
|
|
13
|
-
* @typedef {(_: T) => Sign}
|
|
13
|
+
* @typedef {(_: T) => Sign} Compare
|
|
14
14
|
*/
|
|
15
15
|
|
|
16
|
-
/** @type {<T>(cmp:
|
|
16
|
+
/** @type {<T>(cmp: Compare<T>) => (value: T) => Index3} */
|
|
17
17
|
const index3 = cmp => value => /** @type {Index3} */ (cmp(value) + 1)
|
|
18
18
|
|
|
19
|
-
/** @type {<T>(cmp:
|
|
19
|
+
/** @type {<T>(cmp: Compare<T>) => (v2: Array2<T>) => Index5} */
|
|
20
20
|
const index5 = cmp => ([v0, v1]) => {
|
|
21
21
|
const _0 = cmp(v0)
|
|
22
22
|
return /** @type {Index5} */ (_0 <= 0 ? _0 + 1 : cmp(v1) + 3)
|
|
File without changes
|
|
@@ -26,9 +26,20 @@ const addition = a => b => a + b
|
|
|
26
26
|
/** @type {(value: boolean) => boolean} */
|
|
27
27
|
const logicalNot = v => !v
|
|
28
28
|
|
|
29
|
+
/**
|
|
30
|
+
* @template T
|
|
31
|
+
* @typedef {(a: T) => (b: T) => boolean} EqualOperator
|
|
32
|
+
*/
|
|
33
|
+
|
|
29
34
|
/** @type {<T>(a: T) => (b: T) => boolean} */
|
|
30
35
|
const strictEqual = a => b => a === b
|
|
31
36
|
|
|
37
|
+
/** @type {ReduceOperator<number, number>} */
|
|
38
|
+
const min = a => b => a < b ? a : b
|
|
39
|
+
|
|
40
|
+
/** @type {ReduceOperator<number, number>} */
|
|
41
|
+
const max = a => b => a > b ? a : b
|
|
42
|
+
|
|
32
43
|
module.exports = {
|
|
33
44
|
/** @readonly */
|
|
34
45
|
join,
|
|
@@ -38,4 +49,8 @@ module.exports = {
|
|
|
38
49
|
strictEqual,
|
|
39
50
|
/** @readonly */
|
|
40
51
|
logicalNot,
|
|
52
|
+
/** @readonly */
|
|
53
|
+
min,
|
|
54
|
+
/** @readonly */
|
|
55
|
+
max,
|
|
41
56
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
const option = require("../option")
|
|
2
2
|
const { getVisitor, setVisitor, values } = require("../btree")
|
|
3
|
-
const { cmp } = require("../
|
|
3
|
+
const { cmp } = require("../function/compare")
|
|
4
4
|
const seq = require("../sequence")
|
|
5
5
|
|
|
6
|
-
/** @typedef {import("../
|
|
6
|
+
/** @typedef {import("../function/compare").Sign} Sign */
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* @template T
|
|
@@ -17,7 +17,7 @@ const seq = require("../sequence")
|
|
|
17
17
|
|
|
18
18
|
/**
|
|
19
19
|
* @template T
|
|
20
|
-
* @typedef {import("../
|
|
20
|
+
* @typedef {import("../function/compare").Compare<T>} Cmp
|
|
21
21
|
*/
|
|
22
22
|
|
|
23
23
|
/**
|
|
File without changes
|
|
File without changes
|
|
File without changes
|