functionalscript 0.0.231 → 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 +83 -36
- package/{sequence → types/sequence}/test.js +138 -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,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @template T
|
|
3
|
+
* @typedef {readonly['ok', T]} Ok
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @template E
|
|
8
|
+
* @typedef {readonly['error', E]} Error
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @template T
|
|
13
|
+
* @template E
|
|
14
|
+
* @typedef {Ok<T>|Error<E>} Result
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
/** @type {<T>(value: T) => Ok<T>} */
|
|
18
|
+
const ok = value => ['ok', value]
|
|
19
|
+
|
|
20
|
+
/** @type {<E>(e: E) => Error<E>} */
|
|
21
|
+
const error = e => ['error', e]
|
|
22
|
+
|
|
23
|
+
module.exports = {
|
|
24
|
+
/** @readonly */
|
|
25
|
+
ok,
|
|
26
|
+
/** @readonly */
|
|
27
|
+
error,
|
|
28
|
+
}
|
|
File without changes
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const { compose } = require('../function')
|
|
1
|
+
const { compose, identity } = require('../function')
|
|
2
2
|
const { logicalNot, strictEqual, addition } = require('../function/operator')
|
|
3
3
|
const op = require('../function/operator')
|
|
4
4
|
|
|
@@ -19,7 +19,7 @@ const op = require('../function/operator')
|
|
|
19
19
|
|
|
20
20
|
/**
|
|
21
21
|
* @template T
|
|
22
|
-
* @typedef { readonly[Sequence<T>, Sequence<T>]} Concat<T>
|
|
22
|
+
* @typedef { readonly[Sequence<T>, Sequence<T>] } Concat<T>
|
|
23
23
|
*/
|
|
24
24
|
|
|
25
25
|
/**
|
|
@@ -54,6 +54,9 @@ const fromArray = array => {
|
|
|
54
54
|
/** @type {<T>(sequence: Sequence<T>) => Node<T>} */
|
|
55
55
|
const node = sequence => sequence instanceof Array ? fromArray(sequence) : sequence()
|
|
56
56
|
|
|
57
|
+
/** @type {<T>(a: Sequence<T>) => (b: Sequence<T>) => Thunk<T>} */
|
|
58
|
+
const concat = a => b => () => [a, b]
|
|
59
|
+
|
|
57
60
|
/** @type {<T>(sequence: Sequence<T>) => Result<T>} */
|
|
58
61
|
const next = sequence => {
|
|
59
62
|
let i = sequence
|
|
@@ -66,10 +69,10 @@ const next = sequence => {
|
|
|
66
69
|
i = b
|
|
67
70
|
} else if (aNode instanceof Array) {
|
|
68
71
|
const [aa, ab] = aNode
|
|
69
|
-
i = ()
|
|
72
|
+
i = concat(aa)(concat(ab)(b))
|
|
70
73
|
} else {
|
|
71
74
|
const { first, tail } = aNode
|
|
72
|
-
return { first, tail: ()
|
|
75
|
+
return { first, tail: concat(tail)(b) }
|
|
73
76
|
}
|
|
74
77
|
}
|
|
75
78
|
}
|
|
@@ -79,7 +82,6 @@ const iterable = sequence => ({
|
|
|
79
82
|
*[Symbol.iterator]() {
|
|
80
83
|
let i = sequence
|
|
81
84
|
while (true) {
|
|
82
|
-
if (i instanceof Array) { return yield *i }
|
|
83
85
|
const n = next(i)
|
|
84
86
|
if (n === undefined) { return }
|
|
85
87
|
const { first, tail } = n
|
|
@@ -95,64 +97,73 @@ const toArray = sequence => {
|
|
|
95
97
|
return Array.from(iterable(sequence))
|
|
96
98
|
}
|
|
97
99
|
|
|
98
|
-
/** @type {<I, O>(
|
|
99
|
-
const
|
|
100
|
+
/** @type {<I, O>(step: (result: ResultOne<I>) => Node<O>) => (input: Sequence<I>) => Thunk<O>} */
|
|
101
|
+
const apply = f => input => () => {
|
|
100
102
|
const n = next(input)
|
|
101
103
|
if (n === undefined) { return undefined }
|
|
102
104
|
return f(n)
|
|
103
105
|
}
|
|
104
106
|
|
|
105
107
|
/** @type {<T>(result: ResultOne<Sequence<T>>) => Node<T>} */
|
|
106
|
-
const
|
|
108
|
+
const flatStep = ({first, tail}) => [first, flat(tail)]
|
|
107
109
|
|
|
108
110
|
/** @type {<T>(sequence: Sequence<Sequence<T>>) => Thunk<T>} */
|
|
109
|
-
const flat =
|
|
110
|
-
|
|
111
|
-
/** @type {<T>(...array: readonly Sequence<T>[]) => Thunk<T>} */
|
|
112
|
-
const concat = (...array) => flat(array)
|
|
111
|
+
const flat = apply(flatStep)
|
|
113
112
|
|
|
114
113
|
/** @type {<I, O>(f: (value: I) => O) => (result: ResultOne<I>) => Node<O>} */
|
|
115
|
-
const
|
|
114
|
+
const mapStep = f => ({ first, tail }) => ({ first: f(first), tail: map(f)(tail) })
|
|
116
115
|
|
|
117
116
|
/** @type {<I, O>(f: (value: I) => O) => (input: Sequence<I>) => Thunk<O>} */
|
|
118
|
-
const map = f =>
|
|
117
|
+
const map = f => apply(mapStep(f))
|
|
119
118
|
|
|
120
119
|
/** @type {<I, O>(f: (value: I) => Sequence<O>) => (input: Sequence<I>) => Thunk<O>} */
|
|
121
120
|
const flatMap = f => compose(map(f))(flat)
|
|
122
121
|
|
|
123
122
|
/** @type {<T>(f: (value: T) => boolean) => (result: ResultOne<T>) => Node<T>} */
|
|
124
|
-
const
|
|
123
|
+
const filterStep = f => ({ first, tail }) => {
|
|
125
124
|
const fTail = filter(f)(tail)
|
|
126
125
|
return f(first) ? { first, tail: fTail } : nodeOne(fTail)
|
|
127
126
|
}
|
|
128
127
|
|
|
129
128
|
/** @type {<T>(f: (value: T) => boolean) => (input: Sequence<T>) => Thunk<T>} */
|
|
130
|
-
const filter = f =>
|
|
129
|
+
const filter = f => apply(filterStep(f))
|
|
131
130
|
|
|
132
131
|
/** @type {<I, O>(f: (value: I) => O|undefined) => (result: ResultOne<I>) => Node<O>} */
|
|
133
|
-
const
|
|
132
|
+
const filterMapStep = f => ({first, tail}) => {
|
|
134
133
|
const fFirst = f(first)
|
|
135
134
|
const fTail = filterMap(f)(tail)
|
|
136
135
|
return fFirst === undefined ? nodeOne(fTail) : { first: fFirst, tail: fTail }
|
|
137
136
|
}
|
|
138
137
|
|
|
139
138
|
/** @type {<I, O>(f: (value: I) => O|undefined) => (input: Sequence<I>) => Thunk<O>} */
|
|
140
|
-
const filterMap = f =>
|
|
139
|
+
const filterMap = f => apply(filterMapStep(f))
|
|
141
140
|
|
|
142
141
|
/** @type {<T>(f: (value: T) => boolean) => (result: ResultOne<T>) => Node<T>} */
|
|
143
|
-
const
|
|
142
|
+
const takeWhileStep = f => ({ first, tail }) => f(first) ? { first, tail: takeWhile(f)(tail) } :undefined
|
|
144
143
|
|
|
145
144
|
/** @type {<T>(f: (value: T) => boolean) => (input: Sequence<T>) => Thunk<T>} */
|
|
146
|
-
const takeWhile = f =>
|
|
145
|
+
const takeWhile = f => apply(takeWhileStep(f))
|
|
146
|
+
|
|
147
|
+
/** @type {(n: number) => <T>(result: ResultOne<T>) => Node<T>} */
|
|
148
|
+
const takeStep = n => ({ first, tail }) => 0 < n ? { first, tail: take(n - 1)(tail) } : undefined
|
|
149
|
+
|
|
150
|
+
/** @type {(n: number) => <T>(result: Sequence<T>) => Sequence<T>} */
|
|
151
|
+
const take = n => apply(takeStep(n))
|
|
147
152
|
|
|
148
153
|
/** @type {<T>(f: (value: T) => boolean) => (result: ResultOne<T>) => Node<T>} */
|
|
149
|
-
const
|
|
154
|
+
const dropWhileStep = f => result => {
|
|
150
155
|
const { first, tail } = result
|
|
151
156
|
return f(first) ? nodeOne(dropWhile(f)(tail)) : result
|
|
152
157
|
}
|
|
153
158
|
|
|
154
159
|
/** @type {<T>(f: (value: T) => boolean) => (input: Sequence<T>) => Thunk<T>} */
|
|
155
|
-
const dropWhile = f =>
|
|
160
|
+
const dropWhile = f => apply(dropWhileStep(f))
|
|
161
|
+
|
|
162
|
+
/** @type {(n: number) => <T>(result: ResultOne<T>) => Node<T>} */
|
|
163
|
+
const dropFn = n => result => 0 < n ? nodeOne(drop(n - 1)(result.tail)) : result
|
|
164
|
+
|
|
165
|
+
/** @type {(n: number) => <T>(result: Sequence<T>) => Sequence<T>} */
|
|
166
|
+
const drop = n => apply(dropFn(n))
|
|
156
167
|
|
|
157
168
|
/** @type {<D>(def: D) => <T>(input: Sequence<T>) => D|T} */
|
|
158
169
|
const first = def => input => {
|
|
@@ -180,14 +191,17 @@ const last = def => input => {
|
|
|
180
191
|
/** @type {<D>(def: D) => <T>(f: (value: T) => boolean) => (sequence: Sequence<T>) => D|T} */
|
|
181
192
|
const find = def => f => input => first(def)(filter(f)(input))
|
|
182
193
|
|
|
183
|
-
/** @type {
|
|
184
|
-
const
|
|
194
|
+
/** @type {(value: boolean) => boolean} */
|
|
195
|
+
const boolIdentity = identity
|
|
185
196
|
|
|
186
|
-
/** @type {
|
|
187
|
-
const
|
|
197
|
+
/** @type {(sequence: Sequence<boolean>) => boolean} */
|
|
198
|
+
const some = input => find(false)(boolIdentity)(input)
|
|
199
|
+
|
|
200
|
+
/** @type {(sequence: Sequence<boolean>) => boolean} */
|
|
201
|
+
const every = input => !some(map(logicalNot)(input))
|
|
188
202
|
|
|
189
203
|
/** @type {<T>(value: T) => (sequence: Sequence<T>) => boolean} */
|
|
190
|
-
const includes = value => some(strictEqual(value))
|
|
204
|
+
const includes = value => input => some(map(strictEqual(value))(input))
|
|
191
205
|
|
|
192
206
|
/** @type {(count: number) => Thunk<number>} */
|
|
193
207
|
const countdown = count => () => {
|
|
@@ -213,7 +227,7 @@ const scanFn = operator => ({first, tail}) => {
|
|
|
213
227
|
}
|
|
214
228
|
|
|
215
229
|
/** @type {<T,A>(operator: ScanOperator<T, A>) => (input: Sequence<T>) => Thunk<A>} */
|
|
216
|
-
const scan = operator =>
|
|
230
|
+
const scan = operator => apply(scanFn(operator))
|
|
217
231
|
|
|
218
232
|
/** @type {<T,A>(operator: ScanOperator<T, A>) => <D>(def: D)=> (input: Sequence<T>) => D|A} */
|
|
219
233
|
const scanReduce = operator => def => input => last(def)(scan(operator)(input))
|
|
@@ -227,10 +241,7 @@ const scanReduce = operator => def => input => last(def)(scan(operator)(input))
|
|
|
227
241
|
const scanState = operator => init => [init, scanOperator(operator)(init)]
|
|
228
242
|
|
|
229
243
|
/** @type {<T,A>(operator: ReduceOperator<T, A>) => (init: A) => ScanOperator<T, A>} */
|
|
230
|
-
const scanOperator = operator => init => value =>
|
|
231
|
-
const result = operator(init)(value)
|
|
232
|
-
return scanState(operator)(result)
|
|
233
|
-
}
|
|
244
|
+
const scanOperator = operator => init => value => scanState(operator)(operator(init)(value))
|
|
234
245
|
|
|
235
246
|
/** @type {<T,A>(operator: ReduceOperator<T, A>) => (init: A) => (input: Sequence<T>) => A} */
|
|
236
247
|
const reduce = operator => init => scanReduce(scanOperator(operator)(init))(init)
|
|
@@ -245,6 +256,10 @@ const fold = operator => def => scanReduce(scanState(operator))(def)
|
|
|
245
256
|
|
|
246
257
|
const sum = fold(addition)(0)
|
|
247
258
|
|
|
259
|
+
const min = fold(op.min)(undefined)
|
|
260
|
+
|
|
261
|
+
const max = fold(op.max)(undefined)
|
|
262
|
+
|
|
248
263
|
/** @type {(separator: string) => (input: Sequence<string>) => string} */
|
|
249
264
|
const join = separator => fold(op.join(separator))('')
|
|
250
265
|
|
|
@@ -271,9 +286,29 @@ const reverseOp = prior => value => sequence(value)(prior)
|
|
|
271
286
|
/** @type {<T>(input: Sequence<T>) => Sequence<T>} */
|
|
272
287
|
const reverse = reduce(reverseOp)(empty)
|
|
273
288
|
|
|
289
|
+
/** @type {<A>(a: Sequence<A>) => <B>(b: Sequence<B>) => Thunk<readonly[A, B]>} */
|
|
290
|
+
const zip = a => b => () => {
|
|
291
|
+
const aResult = next(a)
|
|
292
|
+
if (aResult === undefined) { return undefined }
|
|
293
|
+
const bResult = next(b)
|
|
294
|
+
if (bResult === undefined) { return undefined }
|
|
295
|
+
return { first: [aResult.first, bResult.first], tail: zip(aResult.tail)(bResult.tail) }
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
/** @type {<T>(e: op.EqualOperator<T>) => (a: Sequence<T>) => (b: Sequence<T>) => Thunk<boolean>} */
|
|
299
|
+
const equalZip = e => a => b => () => {
|
|
300
|
+
const aResult = next(a)
|
|
301
|
+
const bResult = next(b)
|
|
302
|
+
if (aResult === undefined || bResult === undefined) {
|
|
303
|
+
return { first: aResult === bResult, tail: empty }
|
|
304
|
+
}
|
|
305
|
+
return { first: e(aResult.first)(bResult.first), tail: equalZip(e)(aResult.tail)(bResult.tail) }
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
/** @type {<T>(e: op.EqualOperator<T>) => (a: Sequence<T>) => (b: Sequence<T>) => boolean} */
|
|
309
|
+
const equal = e => a => b => every(equalZip(e)(a)(b))
|
|
310
|
+
|
|
274
311
|
module.exports = {
|
|
275
|
-
/** @readonly */
|
|
276
|
-
empty,
|
|
277
312
|
/** @readonly */
|
|
278
313
|
sequence,
|
|
279
314
|
/** @readonly */
|
|
@@ -309,9 +344,13 @@ module.exports = {
|
|
|
309
344
|
/** @readonly */
|
|
310
345
|
takeWhile,
|
|
311
346
|
/** @readonly */
|
|
347
|
+
take,
|
|
348
|
+
/** @readonly */
|
|
312
349
|
dropWhile,
|
|
313
350
|
/** @readonly */
|
|
314
|
-
|
|
351
|
+
drop,
|
|
352
|
+
/** @readonly */
|
|
353
|
+
scanOperator,
|
|
315
354
|
/** @readonly */
|
|
316
355
|
scanState,
|
|
317
356
|
/** @readonly */
|
|
@@ -323,6 +362,10 @@ module.exports = {
|
|
|
323
362
|
/** @readonly */
|
|
324
363
|
sum,
|
|
325
364
|
/** @readonly */
|
|
365
|
+
min,
|
|
366
|
+
/** @readonly */
|
|
367
|
+
max,
|
|
368
|
+
/** @readonly */
|
|
326
369
|
join,
|
|
327
370
|
/** @readonly */
|
|
328
371
|
entries,
|
|
@@ -331,5 +374,9 @@ module.exports = {
|
|
|
331
374
|
/** @readonly */
|
|
332
375
|
reverse,
|
|
333
376
|
/** @readonly */
|
|
334
|
-
|
|
377
|
+
zip,
|
|
378
|
+
/** @readonly */
|
|
379
|
+
equal,
|
|
380
|
+
/** @readonly */
|
|
381
|
+
countdown,
|
|
335
382
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
const _ = require('.')
|
|
2
|
-
const json = require('
|
|
2
|
+
const json = require('../../json')
|
|
3
3
|
const { sort } = require('../object')
|
|
4
|
-
const { addition } = require('../function/operator')
|
|
4
|
+
const { addition, strictEqual } = require('../function/operator')
|
|
5
5
|
|
|
6
|
-
/** @type {(sequence: _.Sequence<json.
|
|
6
|
+
/** @type {(sequence: _.Sequence<json.Unknown>) => string} */
|
|
7
7
|
const stringify = sequence => json.stringify(sort)(_.toArray(sequence))
|
|
8
8
|
|
|
9
9
|
{
|
|
@@ -17,13 +17,15 @@ const stringify = sequence => json.stringify(sort)(_.toArray(sequence))
|
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
{
|
|
20
|
-
const result = stringify(_.
|
|
20
|
+
const result = stringify(_.flat([[1, 2, 3], [4, 5], [6], [], [7, 8, 9]]))
|
|
21
21
|
if (result !== '[1,2,3,4,5,6,7,8,9]') { throw result }
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
{
|
|
25
|
-
const result = _.concat([1]
|
|
25
|
+
const result = _.concat([1])([2])
|
|
26
26
|
const x = _.next(result)
|
|
27
|
+
if (x === undefined) { throw x }
|
|
28
|
+
if (x.first !== 1) { throw x }
|
|
27
29
|
}
|
|
28
30
|
|
|
29
31
|
{
|
|
@@ -36,6 +38,21 @@ const stringify = sequence => json.stringify(sort)(_.toArray(sequence))
|
|
|
36
38
|
if (result !== '[1,2,3,4,5]') { throw result }
|
|
37
39
|
}
|
|
38
40
|
|
|
41
|
+
{
|
|
42
|
+
const result = stringify(_.take(3)([1, 2, 3, 4, 5, 6, 7, 8, 9]))
|
|
43
|
+
if (result !== '[1,2,3]') { throw result }
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
{
|
|
47
|
+
const result = stringify(_.take(20)([1, 2, 3, 4, 5, 6, 7, 8, 9]))
|
|
48
|
+
if (result !== '[1,2,3,4,5,6,7,8,9]') { throw result }
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
{
|
|
52
|
+
const result = stringify(_.take(0)([1, 2, 3, 4, 5, 6, 7, 8, 9]))
|
|
53
|
+
if (result !== '[]') { throw result }
|
|
54
|
+
}
|
|
55
|
+
|
|
39
56
|
{
|
|
40
57
|
const result = _.find(undefined)(x => x % 2 === 0)([1, 2, 3, 4])
|
|
41
58
|
if (result !== 2) { throw result }
|
|
@@ -51,6 +68,21 @@ const stringify = sequence => json.stringify(sort)(_.toArray(sequence))
|
|
|
51
68
|
if (result !== '[10,11]') { throw result }
|
|
52
69
|
}
|
|
53
70
|
|
|
71
|
+
{
|
|
72
|
+
const result = stringify(_.drop(3)([1, 2, 3, 4, 5, 10, 11]))
|
|
73
|
+
if (result !== '[4,5,10,11]') { throw result }
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
{
|
|
77
|
+
const result = stringify(_.drop(0)([1, 2, 3, 4, 5, 10, 11]))
|
|
78
|
+
if (result !== '[1,2,3,4,5,10,11]') { throw result }
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
{
|
|
82
|
+
const result = stringify(_.drop(10)([1, 2, 3, 4, 5, 10, 11]))
|
|
83
|
+
if (result !== '[]') { throw result }
|
|
84
|
+
}
|
|
85
|
+
|
|
54
86
|
{
|
|
55
87
|
const op = _.scanState(addition)
|
|
56
88
|
const result = stringify(_.scan(op)([2, 3, 4, 5]))
|
|
@@ -102,6 +134,81 @@ const stringify = sequence => json.stringify(sort)(_.toArray(sequence))
|
|
|
102
134
|
if (result !== '[5,4,3,2,1]') { throw result }
|
|
103
135
|
}
|
|
104
136
|
|
|
137
|
+
{
|
|
138
|
+
const result = stringify(_.zip([0, 1, 2])(['a', 'b', 'c', 'd']))
|
|
139
|
+
if (result !== '[[0,"a"],[1,"b"],[2,"c"]]') { throw result }
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
{
|
|
143
|
+
const result = stringify(_.zip([0, 1, 2])(['a', 'b']))
|
|
144
|
+
if (result !== '[[0,"a"],[1,"b"]]') { throw result }
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
{
|
|
148
|
+
const result = _.some(_.map(x => x > 5)([0, 1, 7]))
|
|
149
|
+
if (!result) { throw result}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
{
|
|
153
|
+
const result = _.some(_.map(x => x > 5)([0, 1, 4]))
|
|
154
|
+
if (result) { throw result }
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
{
|
|
158
|
+
const result = _.some(_.map(x => x > 5)([]))
|
|
159
|
+
if (result) { throw result }
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
{
|
|
163
|
+
const result = _.every(_.map(x => x > 5)([0, 1, 7]))
|
|
164
|
+
if (result) { throw result }
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
{
|
|
168
|
+
const result = _.every(_.map(x => x > 5)([6, 11, 7]))
|
|
169
|
+
if (!result) { throw result }
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
{
|
|
173
|
+
const result = _.every(_.map(x => x > 5)([]))
|
|
174
|
+
if (!result) { throw result }
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
{
|
|
178
|
+
const result = _.equal(strictEqual)([1])([2, 3])
|
|
179
|
+
if (result) { throw result}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
{
|
|
183
|
+
const result = _.equal(strictEqual)([1, 3])([1])
|
|
184
|
+
if (result) { throw result }
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
{
|
|
188
|
+
const result = _.equal(strictEqual)([15, 78])([15, 78])
|
|
189
|
+
if (!result) { throw result }
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
{
|
|
193
|
+
const result = _.equal(strictEqual)([])([])
|
|
194
|
+
if (!result) { throw result }
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
{
|
|
198
|
+
const result = _.min([])
|
|
199
|
+
if (result !== undefined) { throw result }
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
{
|
|
203
|
+
const result = _.min([1, 2, 12, -4, 8])
|
|
204
|
+
if (result !== -4) { throw result }
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
{
|
|
208
|
+
const result = _.max([1, 2, 12, -4, 8])
|
|
209
|
+
if (result !== 12) { throw result }
|
|
210
|
+
}
|
|
211
|
+
|
|
105
212
|
// stress tests
|
|
106
213
|
|
|
107
214
|
const stress = () => {
|
|
@@ -129,9 +236,19 @@ const stress = () => {
|
|
|
129
236
|
{
|
|
130
237
|
/** @type {_.Sequence<number>} */
|
|
131
238
|
let sequence = []
|
|
132
|
-
//
|
|
133
|
-
for (let i = 0; i <
|
|
134
|
-
sequence = _.concat(sequence
|
|
239
|
+
// 10_000_000 is too much
|
|
240
|
+
for (let i = 0; i < 5_000_000; ++i) {
|
|
241
|
+
sequence = _.concat(sequence)([i])
|
|
242
|
+
}
|
|
243
|
+
const r = _.toArray(sequence)
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
{
|
|
247
|
+
/** @type {_.Sequence<number>} */
|
|
248
|
+
let sequence = []
|
|
249
|
+
// 4_000_000 is too much
|
|
250
|
+
for (let i = 0; i < 2_000_000; ++i) {
|
|
251
|
+
sequence = _.flat([sequence, [i]])
|
|
135
252
|
}
|
|
136
253
|
const r = _.toArray(sequence)
|
|
137
254
|
}
|
|
@@ -141,7 +258,17 @@ const stress = () => {
|
|
|
141
258
|
let sequence = []
|
|
142
259
|
// 5_000_000 is too much
|
|
143
260
|
for (let i = 0; i < 2_000_000; ++i) {
|
|
144
|
-
sequence = _.
|
|
261
|
+
sequence = _.flat([sequence, [i]])
|
|
262
|
+
}
|
|
263
|
+
const a = _.next(sequence)
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
{
|
|
267
|
+
/** @type {_.Sequence<number>} */
|
|
268
|
+
let sequence = []
|
|
269
|
+
// 20_000_000 is too much
|
|
270
|
+
for (let i = 0; i < 10_000_000; ++i) {
|
|
271
|
+
sequence = _.concat([i])(sequence)
|
|
145
272
|
}
|
|
146
273
|
const a = _.next(sequence)
|
|
147
274
|
}
|
|
@@ -151,7 +278,7 @@ const stress = () => {
|
|
|
151
278
|
let sequence = []
|
|
152
279
|
// 10_000_000 is too much
|
|
153
280
|
for (let i = 0; i < 5_000_000; ++i) {
|
|
154
|
-
sequence = _.
|
|
281
|
+
sequence = _.flat([[i], sequence])
|
|
155
282
|
}
|
|
156
283
|
const a = _.next(sequence)
|
|
157
284
|
}
|
|
@@ -183,4 +310,4 @@ const stress = () => {
|
|
|
183
310
|
|
|
184
311
|
module.exports = {
|
|
185
312
|
|
|
186
|
-
}
|
|
313
|
+
}
|
package/version.js
CHANGED
|
@@ -12,6 +12,6 @@ console.log(`version: ${v}`)
|
|
|
12
12
|
|
|
13
13
|
let package_json = json.parse(fs.readFileSync('package.json').toString())
|
|
14
14
|
|
|
15
|
-
package_json = json.
|
|
15
|
+
package_json = json.setProperty(v)(['version'])(package_json)
|
|
16
16
|
|
|
17
|
-
fs.writeFileSync('package.json', JSON.stringify(package_json, null,
|
|
17
|
+
fs.writeFileSync('package.json', JSON.stringify(package_json, null, 2))
|
package/module-manager/README.md
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
# Module Manager
|
|
2
|
-
|
|
3
|
-
## Module Provider
|
|
4
|
-
|
|
5
|
-
```js
|
|
6
|
-
/** @typedef {(packageName: string) => PackageMap|Package|undefined} PackageMap */
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* @typedef {readonly[
|
|
10
|
-
* string,
|
|
11
|
-
* PackageMap,
|
|
12
|
-
* (fileName: string) => string|undefined
|
|
13
|
-
* ]} Package
|
|
14
|
-
*/
|
|
15
|
-
```
|
|
16
|
-
|
|
17
|
-
## Runner IO
|
|
18
|
-
|
|
19
|
-
The main target of this design is to simplify `RunnerIo` as much as possible.
|
|
20
|
-
|
|
21
|
-
```js
|
|
22
|
-
/**
|
|
23
|
-
* @template T
|
|
24
|
-
* @typedef {readonly[Result<unknown, Error>, Require<T>]} RunnerResult
|
|
25
|
-
*/
|
|
26
|
-
|
|
27
|
-
/** @typedef {<T>(require: Require<T>) => (source: string) => RunnerResult<T>} RunnerIo */
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* @template T
|
|
31
|
-
* @typedef {readonly[(path: string) => RunnerResult<T>, T]} Require<T>
|
|
32
|
-
*/
|
|
33
|
-
```
|
|
34
|
-
|
|
35
|
-
`Require` is using a `Package` and it contains also `RunnerIo` to provide sources also it contains
|
package/module-manager/index.js
DELETED
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
const array = require('../sequence/array')
|
|
2
|
-
const { compose } = require('../function')
|
|
3
|
-
const option = require('../option')
|
|
4
|
-
const { head, last, splitLast, splitFirst } = array
|
|
5
|
-
const iter = require('../sequence/iterable')
|
|
6
|
-
const seq = require('../sequence/operator')
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* @template T
|
|
10
|
-
* @typedef {array.Array<T>} Array
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
/** @typedef {Array<string>} Path */
|
|
14
|
-
|
|
15
|
-
/** @typedef {(_: string) => string|undefined} ReadFile */
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* @typedef {{
|
|
19
|
-
* readonly id: Array<string>
|
|
20
|
-
* readonly dependencies: Dependencies
|
|
21
|
-
* readonly file: ReadFile
|
|
22
|
-
* }} Package
|
|
23
|
-
*/
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* @typedef {{
|
|
27
|
-
* readonly pack: Package,
|
|
28
|
-
* readonly local: Array<string>,
|
|
29
|
-
* }} Location
|
|
30
|
-
*/
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* @typedef {{
|
|
34
|
-
* readonly fileName: string
|
|
35
|
-
* readonly location: Location
|
|
36
|
-
* readonly source: string
|
|
37
|
-
* }} Module
|
|
38
|
-
*/
|
|
39
|
-
|
|
40
|
-
/** @typedef {(_: string) => undefined|Package|Dependencies} Dependencies */
|
|
41
|
-
|
|
42
|
-
/** @type {seq.ExclusiveScan<string, undefined|Path>} */
|
|
43
|
-
const pathNormReduce = seq.exclusiveScan
|
|
44
|
-
(path => item =>
|
|
45
|
-
path === undefined ?
|
|
46
|
-
undefined :
|
|
47
|
-
['', '.'].includes(item) ?
|
|
48
|
-
path :
|
|
49
|
-
item === '..' ?
|
|
50
|
-
head(path) :
|
|
51
|
-
[...path, item])
|
|
52
|
-
([])
|
|
53
|
-
|
|
54
|
-
/** @type {(_: Array<string>) => boolean} */
|
|
55
|
-
const isRelative = localId => ['.', '..'].includes(localId[0])
|
|
56
|
-
|
|
57
|
-
const pathNorm = iter.reduce(pathNormReduce)
|
|
58
|
-
|
|
59
|
-
/** @type {(_: Package) => (_: Path) => Module|undefined} */
|
|
60
|
-
const internal = pack => {
|
|
61
|
-
/** @type {(_: Path) => (_: string) => Module|undefined} */
|
|
62
|
-
const readFile = local => fileName => {
|
|
63
|
-
const source = pack.file([...local, fileName].join('/'))
|
|
64
|
-
return source === undefined ? undefined : { fileName, location: { pack, local }, source}
|
|
65
|
-
}
|
|
66
|
-
return path => {
|
|
67
|
-
/** @type {(_: Path) => Module|undefined} */
|
|
68
|
-
const read = local => {
|
|
69
|
-
/** @type {(_: readonly[Path, string]) => Module|undefined} */
|
|
70
|
-
const tryFiles = ([head, file]) => {
|
|
71
|
-
/** @type {(_: string) => Module|undefined} */
|
|
72
|
-
const one = ext => readFile(head)(file + ext)
|
|
73
|
-
return ['.', '..', '', undefined].includes(last(path)) ? undefined : one('') ?? one('.js')
|
|
74
|
-
}
|
|
75
|
-
return option.map(tryFiles)(splitLast(local)) ?? readFile(local)('index.js')
|
|
76
|
-
}
|
|
77
|
-
return option.map(read)(pathNorm(path))
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
/** @type {(_: Package|Dependencies|undefined) => (_: Path) => Module|undefined} */
|
|
82
|
-
const externalOrInternal = p =>
|
|
83
|
-
p === undefined ? () => undefined : (typeof p === 'function' ? external(p) : internal(p))
|
|
84
|
-
|
|
85
|
-
/** @type {(_: Dependencies) => (path: Path) => Module|undefined} */
|
|
86
|
-
const external = packages => {
|
|
87
|
-
/** @type {(_: readonly [string, Path]) => Module|undefined} */
|
|
88
|
-
const defined = ([first, tail]) => externalOrInternal(packages(first))(tail)
|
|
89
|
-
return path => option.map(defined)(splitFirst(path))
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
/** @type {(_: Location) => (_: string) => Module|undefined} */
|
|
93
|
-
const getModule = ({pack, local}) => path => {
|
|
94
|
-
const pathArray = path.split('/')
|
|
95
|
-
return isRelative(pathArray) ? internal(pack)([...local, ...pathArray]) : external(pack.dependencies)(pathArray)
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
/** @type {(_: Module) => string} */
|
|
99
|
-
const moduleId = module => [...module.location.pack.id, ...module.location.local, module.fileName].join('/')
|
|
100
|
-
|
|
101
|
-
module.exports = {
|
|
102
|
-
/** @readonly */
|
|
103
|
-
isRelative,
|
|
104
|
-
/** @readonly */
|
|
105
|
-
pathNorm,
|
|
106
|
-
/** @readonly */
|
|
107
|
-
getModule,
|
|
108
|
-
/** @readonly */
|
|
109
|
-
moduleId,
|
|
110
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
const m = require('..')
|
|
2
|
-
|
|
3
|
-
/** @type {(_: m.ReadFile) => m.Location} */
|
|
4
|
-
module.exports = readFile => {
|
|
5
|
-
/** @type {(_: string[]) => (_: string) => m.Package|m.Dependencies|undefined} */
|
|
6
|
-
const packages = path => name => {
|
|
7
|
-
const newPath = [...path, name]
|
|
8
|
-
// we only need to check if 'package.json' exist
|
|
9
|
-
return (readFile([...newPath, 'package.json'].join('/')) === undefined ? packages : pack)(newPath)
|
|
10
|
-
}
|
|
11
|
-
/** @type {(_: string[]) => m.Package} */
|
|
12
|
-
const pack = path => ({
|
|
13
|
-
id: path,
|
|
14
|
-
dependencies: packages(['node_modules']),
|
|
15
|
-
file: filePath => readFile([...path, ...filePath.split('/')].join('/'))
|
|
16
|
-
})
|
|
17
|
-
return { pack: pack([]), local: [] }
|
|
18
|
-
}
|