functionalscript 0.0.239 → 0.0.243
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/.github/workflows/node.js.yml +0 -2
- package/LICENSE +21 -201
- package/commonjs/README.md +55 -0
- package/commonjs/module/index.js +23 -10
- package/commonjs/package/dependencies/index.js +1 -1
- package/commonjs/package/dependencies/test.js +0 -3
- package/commonjs/package/index.js +7 -2
- package/commonjs/path/index.js +9 -9
- package/io/nodejs/version/index.js +1 -6
- package/json/index.js +16 -16
- package/package.json +9 -2
- package/test.js +1 -1
- package/tsconfig.json +1 -1
- package/types/array/index.js +1 -1
- package/types/btree/index.js +23 -25
- package/types/btree/test.js +2 -2
- package/types/function/operator/index.js +51 -11
- package/types/list/index.js +372 -0
- package/types/{sequence → list}/test.js +32 -19
- package/types/map/index.js +9 -9
- package/types/map/test.js +11 -11
- package/types/object/index.js +2 -3
- package/types/sequence/README.md +0 -68
- package/types/sequence/index.js +0 -382
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
const _ = require('.')
|
|
2
2
|
const json = require('../../json')
|
|
3
3
|
const { sort } = require('../object')
|
|
4
|
-
const { addition, strictEqual } = require('../function/operator')
|
|
4
|
+
const { addition, strictEqual, foldToScan } = require('../function/operator')
|
|
5
5
|
|
|
6
|
-
/** @type {(sequence: _.
|
|
6
|
+
/** @type {(sequence: _.List<json.Unknown>) => string} */
|
|
7
7
|
const stringify = sequence => json.stringify(sort)(_.toArray(sequence))
|
|
8
8
|
|
|
9
|
+
{
|
|
10
|
+
const x = stringify(_.toArray(_.take(10)(_.cycle([1, 2, 3]))))
|
|
11
|
+
if (x !== '[1,2,3,1,2,3,1,2,3,1]') { throw x }
|
|
12
|
+
}
|
|
13
|
+
|
|
9
14
|
{
|
|
10
15
|
const s = stringify([1, 2, 3])
|
|
11
16
|
if (s !== '[1,2,3]') { throw s }
|
|
@@ -84,7 +89,7 @@ const stringify = sequence => json.stringify(sort)(_.toArray(sequence))
|
|
|
84
89
|
}
|
|
85
90
|
|
|
86
91
|
{
|
|
87
|
-
const op =
|
|
92
|
+
const op = foldToScan(addition)
|
|
88
93
|
const result = stringify(_.scan(op)([2, 3, 4, 5]))
|
|
89
94
|
if (result !== '[2,5,9,14]') { throw result }
|
|
90
95
|
}
|
|
@@ -130,7 +135,7 @@ const stringify = sequence => json.stringify(sort)(_.toArray(sequence))
|
|
|
130
135
|
}
|
|
131
136
|
|
|
132
137
|
{
|
|
133
|
-
const result = stringify(_.reverse([1,2,3,4,5]))
|
|
138
|
+
const result = stringify(_.reverse([1, 2, 3, 4, 5]))
|
|
134
139
|
if (result !== '[5,4,3,2,1]') { throw result }
|
|
135
140
|
}
|
|
136
141
|
|
|
@@ -146,7 +151,7 @@ const stringify = sequence => json.stringify(sort)(_.toArray(sequence))
|
|
|
146
151
|
|
|
147
152
|
{
|
|
148
153
|
const result = _.some(_.map(x => x > 5)([0, 1, 7]))
|
|
149
|
-
if (!result) { throw result}
|
|
154
|
+
if (!result) { throw result }
|
|
150
155
|
}
|
|
151
156
|
|
|
152
157
|
{
|
|
@@ -176,7 +181,7 @@ const stringify = sequence => json.stringify(sort)(_.toArray(sequence))
|
|
|
176
181
|
|
|
177
182
|
{
|
|
178
183
|
const result = _.equal(strictEqual)([1])([2, 3])
|
|
179
|
-
if (result) { throw result}
|
|
184
|
+
if (result) { throw result }
|
|
180
185
|
}
|
|
181
186
|
|
|
182
187
|
{
|
|
@@ -214,8 +219,8 @@ const stringify = sequence => json.stringify(sort)(_.toArray(sequence))
|
|
|
214
219
|
const stress = () => {
|
|
215
220
|
|
|
216
221
|
{
|
|
217
|
-
//
|
|
218
|
-
const n =
|
|
222
|
+
// 200_000_000 is too much
|
|
223
|
+
const n = 100_000_000
|
|
219
224
|
const result = _.toArray(_.countdown(n))
|
|
220
225
|
if (result.length !== n) { throw result.length }
|
|
221
226
|
const len = _.length(_.filter(x => x > n)(result))
|
|
@@ -225,26 +230,30 @@ const stress = () => {
|
|
|
225
230
|
console.log('first')
|
|
226
231
|
|
|
227
232
|
{
|
|
228
|
-
//
|
|
229
|
-
const n =
|
|
233
|
+
// 100_000_000 is too much
|
|
234
|
+
const n = 50_000_000
|
|
230
235
|
const result = _.toArray(_.countdown(n))
|
|
231
236
|
if (result.length !== n) { throw result.length }
|
|
232
237
|
const first = _.first(undefined)(result)
|
|
233
238
|
if (first !== n - 1) { throw first }
|
|
234
239
|
}
|
|
235
240
|
|
|
241
|
+
console.log('concat back')
|
|
242
|
+
|
|
236
243
|
{
|
|
237
|
-
/** @type {_.
|
|
244
|
+
/** @type {_.List<number>} */
|
|
238
245
|
let sequence = []
|
|
239
|
-
//
|
|
240
|
-
for (let i = 0; i <
|
|
246
|
+
// 20_000_000 is too much
|
|
247
|
+
for (let i = 0; i < 10_000_000; ++i) {
|
|
241
248
|
sequence = _.concat(sequence)([i])
|
|
242
249
|
}
|
|
243
250
|
const r = _.toArray(sequence)
|
|
244
251
|
}
|
|
245
252
|
|
|
253
|
+
console.log('flat to Array')
|
|
254
|
+
|
|
246
255
|
{
|
|
247
|
-
/** @type {_.
|
|
256
|
+
/** @type {_.List<number>} */
|
|
248
257
|
let sequence = []
|
|
249
258
|
// 4_000_000 is too much
|
|
250
259
|
for (let i = 0; i < 2_000_000; ++i) {
|
|
@@ -253,18 +262,22 @@ const stress = () => {
|
|
|
253
262
|
const r = _.toArray(sequence)
|
|
254
263
|
}
|
|
255
264
|
|
|
265
|
+
console.log('flat next')
|
|
266
|
+
|
|
256
267
|
{
|
|
257
|
-
/** @type {_.
|
|
268
|
+
/** @type {_.List<number>} */
|
|
258
269
|
let sequence = []
|
|
259
270
|
// 5_000_000 is too much
|
|
260
|
-
for (let i = 0; i <
|
|
271
|
+
for (let i = 0; i < 4_000_000; ++i) {
|
|
261
272
|
sequence = _.flat([sequence, [i]])
|
|
262
273
|
}
|
|
263
274
|
const a = _.next(sequence)
|
|
264
275
|
}
|
|
265
276
|
|
|
277
|
+
console.log('concat front')
|
|
278
|
+
|
|
266
279
|
{
|
|
267
|
-
/** @type {_.
|
|
280
|
+
/** @type {_.List<number>} */
|
|
268
281
|
let sequence = []
|
|
269
282
|
// 20_000_000 is too much
|
|
270
283
|
for (let i = 0; i < 10_000_000; ++i) {
|
|
@@ -274,7 +287,7 @@ const stress = () => {
|
|
|
274
287
|
}
|
|
275
288
|
|
|
276
289
|
{
|
|
277
|
-
/** @type {_.
|
|
290
|
+
/** @type {_.List<number>} */
|
|
278
291
|
let sequence = []
|
|
279
292
|
// 10_000_000 is too much
|
|
280
293
|
for (let i = 0; i < 5_000_000; ++i) {
|
|
@@ -306,7 +319,7 @@ const stress = () => {
|
|
|
306
319
|
}
|
|
307
320
|
}
|
|
308
321
|
|
|
309
|
-
|
|
322
|
+
stress()
|
|
310
323
|
|
|
311
324
|
module.exports = {
|
|
312
325
|
|
package/types/map/index.js
CHANGED
|
@@ -3,7 +3,7 @@ const btree = require('../btree')
|
|
|
3
3
|
const { getVisitor, setVisitor, values } = require("../btree")
|
|
4
4
|
const compare = require("../function/compare")
|
|
5
5
|
const { cmp } = require("../function/compare")
|
|
6
|
-
const seq = require("../
|
|
6
|
+
const seq = require("../list")
|
|
7
7
|
|
|
8
8
|
/** @typedef {compare.Sign} Sign */
|
|
9
9
|
|
|
@@ -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
|
|
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] }
|
|
@@ -54,16 +54,16 @@ const insert = name => value => map => {
|
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
-
/** @type {<T>(map: Map<T>) => seq.
|
|
57
|
+
/** @type {<T>(map: Map<T>) => seq.List<Entry<T>>} */
|
|
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
|
|
61
|
+
const setOp = map => ([name, value]) => set(name)(value)(map)
|
|
62
62
|
|
|
63
|
-
/** @type {<T>(entries: seq.
|
|
63
|
+
/** @type {<T>(entries: seq.List<Entry<T>>) => Map<T>} */
|
|
64
64
|
const fromEntries = entries => {
|
|
65
|
-
/** @typedef {typeof entries extends seq.
|
|
66
|
-
return seq.reduce(
|
|
65
|
+
/** @typedef {typeof entries extends seq.List<Entry<infer T>> ? T : never} T */
|
|
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
|
-
|
|
76
|
-
/** @
|
|
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,
|
|
2
|
-
const
|
|
1
|
+
const { at, set, empty, entries } = require('.')
|
|
2
|
+
const seq = require('../list')
|
|
3
3
|
|
|
4
4
|
{
|
|
5
|
-
let m =
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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 =
|
|
45
|
-
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 =
|
|
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 =
|
|
57
|
+
m = set((i * i).toString())(i)(m)
|
|
58
58
|
/*
|
|
59
59
|
console.log()
|
|
60
60
|
console.log(`# ${i}`)
|
package/types/object/index.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
const seq = require('../
|
|
1
|
+
const seq = require('../list')
|
|
2
2
|
const map = require('../map')
|
|
3
|
-
const { compose } = require('../function')
|
|
4
3
|
|
|
5
4
|
/**
|
|
6
5
|
* @template T
|
|
@@ -17,7 +16,7 @@ const { compose } = require('../function')
|
|
|
17
16
|
/** @type {(name: string) => <T>(object: Map<T>) => T|undefined} */
|
|
18
17
|
const at = name => object => Object.getOwnPropertyDescriptor(object, name)?.value
|
|
19
18
|
|
|
20
|
-
/** @type {<T>(entries: seq.
|
|
19
|
+
/** @type {<T>(entries: seq.List<Entry<T>>) => seq.List<Entry<T>>} */
|
|
21
20
|
const sort = entries => map.entries(map.fromEntries(entries))
|
|
22
21
|
|
|
23
22
|
module.exports = {
|
package/types/sequence/README.md
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
# Sequences
|
|
2
|
-
|
|
3
|
-
Sequence types:
|
|
4
|
-
|
|
5
|
-
- Sequence
|
|
6
|
-
- Array
|
|
7
|
-
- Iterable
|
|
8
|
-
- AsyncIterable
|
|
9
|
-
|
|
10
|
-
# Sequence Types
|
|
11
|
-
|
|
12
|
-
```ts
|
|
13
|
-
type Sequence<T> =
|
|
14
|
-
readonly T[] |
|
|
15
|
-
Thunk<T> |
|
|
16
|
-
|
|
17
|
-
type Thunk<T> = () => Node<T>
|
|
18
|
-
|
|
19
|
-
type Node<T> =
|
|
20
|
-
undefined |
|
|
21
|
-
{ readonly first: T, readonly tail: Sequence<T> } |
|
|
22
|
-
readonly[Sequence<T>, Sequence<T>]
|
|
23
|
-
```
|
|
24
|
-
|
|
25
|
-
## Functions
|
|
26
|
-
|
|
27
|
-
See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array
|
|
28
|
-
|
|
29
|
-
- `length: Sequence<infer T> => number`
|
|
30
|
-
- `at: number => Sequence<infer T> = T|undefined`
|
|
31
|
-
- `concat: Sequence<infer T> => Sequence<T> => Sequence<T>`
|
|
32
|
-
- `entries: Sequence<infer T> => Sequence<[number, T]>`
|
|
33
|
-
- `every: (infer T => boolean) => Sequence<T> => boolean`
|
|
34
|
-
- `filter: (infer T => boolean) => Sequence<T> => Sequence<T>`
|
|
35
|
-
- `find: (infer T => boolean) => Sequence<T> => T`
|
|
36
|
-
- `findIndex: (infer T => boolean) => Sequence<T> => number`
|
|
37
|
-
- `flat: Sequence<Sequence<T>> => Sequence<T>`
|
|
38
|
-
- `flatMap: (infer T => Sequence<infer R>) => Sequence<T> => Sequence<R>`
|
|
39
|
-
- `includes: infer T => Sequence<T> => boolean`
|
|
40
|
-
- `indexOf: infer T => Sequence<T> => number`
|
|
41
|
-
- `join: string => Sequence<string> => string`
|
|
42
|
-
- `lastIndexOf: infer T => Sequence<T> => number`
|
|
43
|
-
- `map: (infer T => infer R) => Sequence<T> => Sequence<R>`
|
|
44
|
-
- `reduce: ...Scan<T, R> => Sequence<T> => R`
|
|
45
|
-
- `some: (infer T => boolean) => Sequence<T> => boolean`
|
|
46
|
-
|
|
47
|
-
### Priority 2.
|
|
48
|
-
|
|
49
|
-
- `slice: number => number => Sequence<T> => Sequence<T>`
|
|
50
|
-
- `reduceRight: ...Scan<T, R> => Sequence<T> => R`
|
|
51
|
-
- `toLocalString: Locales => Sequence<T> => string`
|
|
52
|
-
|
|
53
|
-
### Priority 3.
|
|
54
|
-
|
|
55
|
-
- `keys: Sequence<T> => Sequence<string>`
|
|
56
|
-
- `values: Sequence<infer T> => Sequence<T>`
|
|
57
|
-
|
|
58
|
-
## Prohibited Array Operations
|
|
59
|
-
|
|
60
|
-
- `copyWithin`
|
|
61
|
-
- `fill`
|
|
62
|
-
- `pop`
|
|
63
|
-
- `push`
|
|
64
|
-
- `reverse`
|
|
65
|
-
- `shift`
|
|
66
|
-
- `sort`
|
|
67
|
-
- `splice`
|
|
68
|
-
- `unshift`
|