functionalscript 0.0.229 → 0.0.233
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/package/index.js +72 -0
- package/commonjs/package/test.js +33 -0
- package/commonjs/path/index.js +66 -0
- package/commonjs/path/test.js +47 -0
- package/commonjs/run/index.js +17 -0
- package/io/commonjs/index.js +28 -0
- package/io/commonjs/test.js +72 -0
- package/io/result/index.js +15 -0
- package/json/index.js +29 -29
- package/json/test.js +9 -9
- package/package.json +23 -23
- package/test.js +5 -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 +36 -0
- package/{sequence → types/sequence}/README.md +0 -0
- package/{sequence → types/sequence}/index.js +99 -50
- 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
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
const i = require('.')
|
|
2
|
-
const { compose } = require('../../function')
|
|
3
|
-
|
|
4
|
-
{
|
|
5
|
-
const r = i.sum([120, 300, 42])
|
|
6
|
-
if (r !== 462) { throw 'error' }
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
{
|
|
10
|
-
if (i.sum([1, 2]) !== 3) { throw 'error' }
|
|
11
|
-
if (i.sum([1, 2]) !== 3) { throw 'error' }
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
{
|
|
15
|
-
const x = Array.from(i.map(a => a ** 2)([1, 2, 3]))
|
|
16
|
-
if (x.length !== 3) { throw 'error' }
|
|
17
|
-
if (x[0] !== 1) { throw 'error' }
|
|
18
|
-
if (x[1] !== 4) { throw 'error' }
|
|
19
|
-
if (x[2] !== 9) { throw 'error' }
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
{
|
|
23
|
-
if (i.join('/')([]) !== '') { throw 'error' }
|
|
24
|
-
if (i.join('/')(['a']) !== 'a') { throw 'error' }
|
|
25
|
-
if (i.join('/')(['a', 'b']) !== 'a/b') { throw 'error'}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
{
|
|
29
|
-
if (i.find(x => x === 'c')(['a', 'b', 'c']) !== 'c') { throw 'error' }
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
{
|
|
33
|
-
/** @type {(_: string) => string|undefined} */
|
|
34
|
-
const file = _ => 'x'
|
|
35
|
-
/** @type {(_: string) => string|undefined} */
|
|
36
|
-
const x = p => compose
|
|
37
|
-
(i.map(x => file(x())))
|
|
38
|
-
(i.find(x => x !== undefined))
|
|
39
|
-
([() => p, () => `${p}.js`, () => `${p}/index.js`])
|
|
40
|
-
if (x('index.js') !== 'x') { throw 'error' }
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
{
|
|
44
|
-
const x = JSON.stringify(Array.from(i.entries(['a', 'b', 'c'])))
|
|
45
|
-
if (x !== '[[0,"a"],[1,"b"],[2,"c"]]') { throw x }
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
{
|
|
49
|
-
const x = JSON.stringify(Array.from(i.entries([])))
|
|
50
|
-
if (x !== '[]') { throw x }
|
|
51
|
-
}
|
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
const op = require('../../function/operator')
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* @template T0
|
|
5
|
-
* @template T1
|
|
6
|
-
* @typedef {import('../array').Tuple2<T0, T1>} Tuple2
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* @template T
|
|
11
|
-
* @template R
|
|
12
|
-
* @typedef {Tuple2<R, Scan<T, R>>} ScanResult
|
|
13
|
-
*/
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* @template T
|
|
17
|
-
* @template R
|
|
18
|
-
* @typedef {(value: T) => ScanResult<T, R>} Scan
|
|
19
|
-
*/
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* @template T
|
|
23
|
-
* @template R
|
|
24
|
-
* @typedef {Tuple2<R, Scan<T, R>>} ExclusiveScan
|
|
25
|
-
*/
|
|
26
|
-
|
|
27
|
-
/** @type {<R, T>(operator: op.ReduceOperator<R, T>) => (prior: R) => Scan<T, R>} */
|
|
28
|
-
const scan = operator => {
|
|
29
|
-
/** @typedef {typeof operator extends op.ReduceOperator<infer R, infer T> ? [R, T] : never} RT */
|
|
30
|
-
/** @typedef {RT[0]} R */
|
|
31
|
-
/** @typedef {RT[1]} T */
|
|
32
|
-
/** @type {(prior: R) => Scan<T, R>} */
|
|
33
|
-
const f = prior => value => {
|
|
34
|
-
const result = operator(prior)(value)
|
|
35
|
-
return [result, f(result)]
|
|
36
|
-
}
|
|
37
|
-
return f
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/** @type {<R, T>(operator: op.ReduceOperator<R, T>) => (first: R) => ExclusiveScan<T, R>} */
|
|
41
|
-
const exclusiveScan = operator => first => [first, scan(operator)(first)]
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* @template T
|
|
45
|
-
* @typedef {Tuple2<number, T>} Entry
|
|
46
|
-
*/
|
|
47
|
-
|
|
48
|
-
/** @type {(index: number) => <T>(value: T) => ScanResult<T, Entry<T>>} */
|
|
49
|
-
const createEntries = index => value => [[index, value], createEntries(index + 1)]
|
|
50
|
-
|
|
51
|
-
const entries = createEntries(0)
|
|
52
|
-
|
|
53
|
-
/** @type {(separator: string) => ExclusiveScan<string, string>} */
|
|
54
|
-
const join = separator => ['', value => [value, scan(op.join(separator))(value)]]
|
|
55
|
-
|
|
56
|
-
const sum = exclusiveScan(op.addition)(0)
|
|
57
|
-
|
|
58
|
-
/** @type {(a: number) => () => number} */
|
|
59
|
-
const counter = a => () => a + 1
|
|
60
|
-
|
|
61
|
-
const length = exclusiveScan(counter)(0)
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* @template T
|
|
65
|
-
* @template R
|
|
66
|
-
* @typedef {(value: T) => R} Func
|
|
67
|
-
*/
|
|
68
|
-
|
|
69
|
-
/** @type {<T, R, X>(flatMap: (f: Func<T, readonly[R]>) => X) => (f: Func<T, R>) =>X} */
|
|
70
|
-
const map = flatMap => f => flatMap(x => [f(x)])
|
|
71
|
-
|
|
72
|
-
/** @type {<T, X>(flatMap: (f: Func<T, readonly[T]|[]>) => X) => (f: Func<T, boolean>) =>X} */
|
|
73
|
-
const filter = flatMap => f => flatMap(x => f(x) ? [x] : [])
|
|
74
|
-
|
|
75
|
-
module.exports = {
|
|
76
|
-
/** @readonly */
|
|
77
|
-
exclusiveScan,
|
|
78
|
-
/** @readonly */
|
|
79
|
-
scan,
|
|
80
|
-
/** @readonly */
|
|
81
|
-
join,
|
|
82
|
-
/** @readonly */
|
|
83
|
-
sum,
|
|
84
|
-
/** @readonly */
|
|
85
|
-
length,
|
|
86
|
-
/** @readonly */
|
|
87
|
-
entries,
|
|
88
|
-
/** @readonly */
|
|
89
|
-
map,
|
|
90
|
-
/** @readonly */
|
|
91
|
-
filter,
|
|
92
|
-
}
|