functionalscript 0.0.400 → 0.0.403
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/build/module.f.cjs +1 -1
- package/commonjs/path/module.f.cjs +2 -2
- package/json/module.f.cjs +2 -2
- package/package.json +1 -1
- package/test.f.cjs +1 -1
- package/text/encoding/module.f.cjs +2 -2
- package/types/bigint/module.f.cjs +2 -2
- package/types/btree/remove/module.f.cjs +2 -2
- package/types/btree/set/module.f.cjs +2 -2
- package/types/function/operator/module.f.cjs +15 -15
- package/types/list/module.f.cjs +13 -15
- package/types/list/test.f.cjs +4 -4
- package/types/map/module.f.cjs +6 -6
- package/types/map/test.f.cjs +2 -2
- package/types/module.f.cjs +1 -1
- package/types/number/module.f.cjs +4 -4
- package/types/string/module.f.cjs +5 -5
- package/types/{string_set → stringset}/module.f.cjs +6 -3
- /package/types/{string_set → stringset}/test.f.cjs +0 -0
|
@@ -8,7 +8,7 @@ const object = require('../../types/object/module.f.cjs')
|
|
|
8
8
|
const { fromMap } = object
|
|
9
9
|
const path = require('../path/module.f.cjs')
|
|
10
10
|
const { parseAndFind } = path
|
|
11
|
-
const stringSet = require('../../types/
|
|
11
|
+
const stringSet = require('../../types/stringset/module.f.cjs')
|
|
12
12
|
const { set: setSet, contains: setContains } = stringSet
|
|
13
13
|
|
|
14
14
|
/**
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const list = require("../../types/list/module.f.cjs")
|
|
2
|
-
const { next,
|
|
2
|
+
const { next, fold, reverse, first, flat, toArray, filterMap, isEmpty, concat } = list
|
|
3
3
|
const { join } = require('../../types/string/module.f.cjs')
|
|
4
4
|
const package_ = require("../package/module.f.cjs")
|
|
5
5
|
const module_ = require("../module/module.f.cjs")
|
|
@@ -38,7 +38,7 @@ const normItemsOp = first => prior => {
|
|
|
38
38
|
|
|
39
39
|
/** @type {(items: list.List<string>) => OptionList} */
|
|
40
40
|
const normItems = items => {
|
|
41
|
-
const result =
|
|
41
|
+
const result = fold(normItemsOp)([undefined])(items)
|
|
42
42
|
return result === undefined ? result : [reverse(result[0])]
|
|
43
43
|
}
|
|
44
44
|
|
package/json/module.f.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const list = require('../types/list/module.f.cjs')
|
|
2
|
-
const { next, flat, fold, map } = list
|
|
2
|
+
const { next, flat, reduce: fold, map } = list
|
|
3
3
|
const { concat } = require('../types/string/module.f.cjs')
|
|
4
4
|
const object = require('../types/object/module.f.cjs')
|
|
5
5
|
const { at } = object
|
|
@@ -50,7 +50,7 @@ const boolSerialize = value => value ? trueSerialize : falseSerialize
|
|
|
50
50
|
const colon = [':']
|
|
51
51
|
const comma = [',']
|
|
52
52
|
|
|
53
|
-
/** @type {operator.
|
|
53
|
+
/** @type {operator.Reduce<list.List<string>>} */
|
|
54
54
|
const joinOp = b => prior => flat([prior, comma, b])
|
|
55
55
|
|
|
56
56
|
/** @type {(input: list.List<list.List<string>>) => list.List<string>} */
|
package/package.json
CHANGED
package/test.f.cjs
CHANGED
|
@@ -16,7 +16,7 @@ require('./commonjs/package/test.f.cjs')
|
|
|
16
16
|
require('./commonjs/path/test.f.cjs')
|
|
17
17
|
require('./types/function/test.f.cjs')
|
|
18
18
|
require('./types/function/compare/test.f.cjs')
|
|
19
|
-
require('./types/
|
|
19
|
+
require('./types/stringset/test.f.cjs')
|
|
20
20
|
require('./types/option/test.f.cjs')
|
|
21
21
|
require('./commonjs/build/test.f.cjs')
|
|
22
22
|
require('./types/range/test.f.cjs')
|
|
@@ -4,7 +4,7 @@ const operator = require('../../types/function/operator/module.f.cjs')
|
|
|
4
4
|
const array = require('../../types/array/module.f.cjs')
|
|
5
5
|
const { contains } = require('../../types/range/module.f.cjs')
|
|
6
6
|
const { compose } = require('../../types/function/module.f.cjs')
|
|
7
|
-
const { map, flat, stateScan, concat,
|
|
7
|
+
const { map, flat, stateScan, concat, reduce, toArray, flatMap } = list
|
|
8
8
|
const { ok, error } = result
|
|
9
9
|
|
|
10
10
|
/** @typedef {result.Result<number,number>} ByteResult */
|
|
@@ -136,7 +136,7 @@ const stringToUtf16List = s => {
|
|
|
136
136
|
return at(0)
|
|
137
137
|
}
|
|
138
138
|
|
|
139
|
-
const utf16ListToString = compose(map(String.fromCharCode))(
|
|
139
|
+
const utf16ListToString = compose(map(String.fromCharCode))(reduce(operator.concat)(''))
|
|
140
140
|
|
|
141
141
|
module.exports = {
|
|
142
142
|
/** @readonly */
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
const {
|
|
1
|
+
const { reduce } = require('../list/module.f.cjs')
|
|
2
2
|
|
|
3
3
|
/** @type {(a: bigint) => (b: bigint) => bigint} */
|
|
4
4
|
const addition = a => b => a + b
|
|
5
5
|
|
|
6
|
-
const sum =
|
|
6
|
+
const sum = reduce(addition)(0n)
|
|
7
7
|
|
|
8
8
|
module.exports = {
|
|
9
9
|
/** @readonly */
|
|
@@ -2,7 +2,7 @@ const _ = require('../types/module.f.cjs')
|
|
|
2
2
|
const cmp = require('../../function/compare/module.f.cjs')
|
|
3
3
|
const find = require('../find/module.f.cjs')
|
|
4
4
|
const list = require('../../list/module.f.cjs')
|
|
5
|
-
const {
|
|
5
|
+
const { fold, concat, next } = list
|
|
6
6
|
const array = require('../../array/module.f.cjs')
|
|
7
7
|
const { map } = require('../../option/module.f.cjs')
|
|
8
8
|
|
|
@@ -111,7 +111,7 @@ const reduceX = ms => ([i, n]) => a => {
|
|
|
111
111
|
}
|
|
112
112
|
}
|
|
113
113
|
|
|
114
|
-
const reduce =
|
|
114
|
+
const reduce = fold(reduceX([reduceValue0, reduceValue2]))
|
|
115
115
|
|
|
116
116
|
const initReduce = reduceX([initValue0, initValue1])
|
|
117
117
|
|
|
@@ -3,7 +3,7 @@ const btreeFind = require('../find/module.f.cjs')
|
|
|
3
3
|
const { find } = btreeFind
|
|
4
4
|
const cmp = require('../../function/compare/module.f.cjs')
|
|
5
5
|
const list = require('../../list/module.f.cjs')
|
|
6
|
-
const {
|
|
6
|
+
const { fold } = list
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* @template T
|
|
@@ -34,7 +34,7 @@ const reduceOp = ([i, x]) => a => {
|
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
const reduceBranch =
|
|
37
|
+
const reduceBranch = fold(reduceOp)
|
|
38
38
|
|
|
39
39
|
/** @type {<T>(c: cmp.Compare<T>) => (g: (value?: T) => T) => (node: _.Node<T>) => _.Node<T>} */
|
|
40
40
|
const nodeSet = c => g => node => {
|
|
@@ -7,13 +7,13 @@
|
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* @template I,O
|
|
10
|
-
* @typedef {Binary<I, O, O>}
|
|
10
|
+
* @typedef {Binary<I, O, O>} FoldT
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
-
/** @type {(separator: string) =>
|
|
13
|
+
/** @type {(separator: string) => Reduce<string>} */
|
|
14
14
|
const join = separator => value => prior => `${prior}${separator}${value}`
|
|
15
15
|
|
|
16
|
-
/** @type {
|
|
16
|
+
/** @type {Reduce<string>} */
|
|
17
17
|
const concat = i => acc => `${acc}${i}`
|
|
18
18
|
|
|
19
19
|
/**
|
|
@@ -49,27 +49,27 @@ const stateScanToScan = op => prior => i => {
|
|
|
49
49
|
return [o, stateScanToScan(op)(s)]
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
-
/** @type {<I, O>(
|
|
53
|
-
const
|
|
54
|
-
const result =
|
|
55
|
-
return [result,
|
|
52
|
+
/** @type {<I, O>(fold: FoldT<I, O>) => (prior: O) => Scan<I, O>} */
|
|
53
|
+
const foldToScan = fold => prior => i => {
|
|
54
|
+
const result = fold(i)(prior)
|
|
55
|
+
return [result, foldToScan(fold)(result)]
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
/**
|
|
59
59
|
* @template T
|
|
60
|
-
* @typedef {
|
|
60
|
+
* @typedef {FoldT<T, T>} Reduce
|
|
61
61
|
*/
|
|
62
62
|
|
|
63
|
-
/** @type {<T>(fold:
|
|
64
|
-
const
|
|
63
|
+
/** @type {<T>(fold: Reduce<T>) => Scan<T, T>} */
|
|
64
|
+
const reduceToScan = op => init => [init, foldToScan(op)(init)]
|
|
65
65
|
|
|
66
|
-
/** @type {
|
|
66
|
+
/** @type {Reduce<number>} */
|
|
67
67
|
const addition = a => b => a + b
|
|
68
68
|
|
|
69
|
-
/** @type {
|
|
69
|
+
/** @type {Reduce<number>} */
|
|
70
70
|
const min = a => b => a < b ? a : b
|
|
71
71
|
|
|
72
|
-
/** @type {
|
|
72
|
+
/** @type {Reduce<number>} */
|
|
73
73
|
const max = a => b => a > b ? a : b
|
|
74
74
|
|
|
75
75
|
const increment = addition(1)
|
|
@@ -94,10 +94,10 @@ module.exports = {
|
|
|
94
94
|
/** @readonly */
|
|
95
95
|
stateScanToScan,
|
|
96
96
|
/** @readonly */
|
|
97
|
-
reduceToScan,
|
|
98
|
-
/** @readonly */
|
|
99
97
|
foldToScan,
|
|
100
98
|
/** @readonly */
|
|
99
|
+
reduceToScan,
|
|
100
|
+
/** @readonly */
|
|
101
101
|
counter,
|
|
102
102
|
/** @readonly */
|
|
103
103
|
concat,
|
package/types/list/module.f.cjs
CHANGED
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
const { compose, identity } = require('../function/module.f.cjs')
|
|
2
2
|
const operator = require('../function/operator/module.f.cjs')
|
|
3
3
|
const {
|
|
4
|
-
join: joinOp,
|
|
5
|
-
concat: concatOp,
|
|
6
4
|
counter,
|
|
7
5
|
logicalNot,
|
|
8
6
|
strictEqual,
|
|
9
7
|
stateScanToScan,
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
foldToScan,
|
|
9
|
+
reduceToScan
|
|
12
10
|
} = operator
|
|
13
11
|
|
|
14
12
|
/**
|
|
@@ -252,18 +250,18 @@ const scan = op => apply(scanStep(op))
|
|
|
252
250
|
/** @type {<I, S, O>(op: operator.StateScan<I, S, O>) => (init: S) => (input: List<I>) => Thunk<O>} */
|
|
253
251
|
const stateScan = op => init => scan(stateScanToScan(op)(init))
|
|
254
252
|
|
|
255
|
-
/** @type {<I,O>(op: operator.
|
|
256
|
-
const
|
|
253
|
+
/** @type {<I,O>(op: operator.FoldT<I, O>) => (init: O) => (input: List<I>) => Thunk<O>} */
|
|
254
|
+
const foldScan = op => init => scan(foldToScan(op)(init))
|
|
257
255
|
|
|
258
|
-
/** @type {<I,O>(op: operator.
|
|
259
|
-
const
|
|
256
|
+
/** @type {<I,O>(op: operator.FoldT<I, O>) => (init: O) => (input: List<I>) => O} */
|
|
257
|
+
const fold = op => init => input => last(init)(foldScan(op)(init)(input))
|
|
260
258
|
|
|
261
|
-
/** @type {<T>(op: operator.
|
|
262
|
-
const
|
|
259
|
+
/** @type {<T>(op: operator.Reduce<T>) => <D>(def: D) => (input: List<T>) => D|T} */
|
|
260
|
+
const reduce = op => def => input => last(def)(scan(reduceToScan(op))(input))
|
|
263
261
|
|
|
264
262
|
|
|
265
263
|
/** @type {<T>(input: List<T>) => number} */
|
|
266
|
-
const length =
|
|
264
|
+
const length = fold(counter)(0)
|
|
267
265
|
|
|
268
266
|
/**
|
|
269
267
|
* @template T
|
|
@@ -285,7 +283,7 @@ const entries = input => {
|
|
|
285
283
|
const reverseOperator = first => tail => ({ first, tail })
|
|
286
284
|
|
|
287
285
|
/** @type {<T>(input: List<T>) => List<T>} */
|
|
288
|
-
const reverse =
|
|
286
|
+
const reverse = fold(reverseOperator)(undefined)
|
|
289
287
|
|
|
290
288
|
/** @type {<A>(a: List<A>) => <B>(b: List<B>) => List<readonly[A, B]>} */
|
|
291
289
|
const zip = a => b => () => {
|
|
@@ -361,12 +359,12 @@ module.exports = {
|
|
|
361
359
|
/** @readonly */
|
|
362
360
|
stateScan,
|
|
363
361
|
/** @readonly */
|
|
364
|
-
|
|
365
|
-
/** @readonly */
|
|
366
|
-
reduce,
|
|
362
|
+
foldScan,
|
|
367
363
|
/** @readonly */
|
|
368
364
|
fold,
|
|
369
365
|
/** @readonly */
|
|
366
|
+
reduce,
|
|
367
|
+
/** @readonly */
|
|
370
368
|
length,
|
|
371
369
|
/** @readonly */
|
|
372
370
|
entries,
|
package/types/list/test.f.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const _ = require('./module.f.cjs')
|
|
2
2
|
const json = require('../../json/module.f.cjs')
|
|
3
3
|
const { sort } = require('../object/module.f.cjs')
|
|
4
|
-
const { addition, strictEqual,
|
|
4
|
+
const { addition, strictEqual, reduceToScan } = require('../function/operator/module.f.cjs')
|
|
5
5
|
|
|
6
6
|
/** @type {(sequence: _.List<json.Unknown>) => string} */
|
|
7
7
|
const stringify = sequence => json.stringify(sort)(_.toArray(sequence))
|
|
@@ -94,18 +94,18 @@ const stringify = sequence => json.stringify(sort)(_.toArray(sequence))
|
|
|
94
94
|
}
|
|
95
95
|
|
|
96
96
|
{
|
|
97
|
-
const op =
|
|
97
|
+
const op = reduceToScan(addition)
|
|
98
98
|
const result = stringify(_.scan(op)([2, 3, 4, 5]))
|
|
99
99
|
if (result !== '[2,5,9,14]') { throw result }
|
|
100
100
|
}
|
|
101
101
|
|
|
102
102
|
{
|
|
103
|
-
const result = _.
|
|
103
|
+
const result = _.reduce(addition)(undefined)([2, 3, 4, 5])
|
|
104
104
|
if (result !== 14) { throw result }
|
|
105
105
|
}
|
|
106
106
|
|
|
107
107
|
{
|
|
108
|
-
const result = _.
|
|
108
|
+
const result = _.reduce(addition)(undefined)([])
|
|
109
109
|
if (result !== undefined) { throw result }
|
|
110
110
|
}
|
|
111
111
|
|
package/types/map/module.f.cjs
CHANGED
|
@@ -6,7 +6,7 @@ const btreeSet = require('../btree/set/module.f.cjs').set
|
|
|
6
6
|
const compare = require('../function/compare/module.f.cjs')
|
|
7
7
|
const { cmp } = require('../string/module.f.cjs')
|
|
8
8
|
const list = require('../list/module.f.cjs')
|
|
9
|
-
const {
|
|
9
|
+
const { fold } = list
|
|
10
10
|
const { remove: btreeRemove } = require('../btree/remove/module.f.cjs')
|
|
11
11
|
const operator = require('../function/operator/module.f.cjs')
|
|
12
12
|
|
|
@@ -37,11 +37,11 @@ const at = name => map => {
|
|
|
37
37
|
return result === undefined ? undefined : result[1]
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
/** @type {<T>(o: operator.
|
|
40
|
+
/** @type {<T>(o: operator.Reduce<T>) => (entry: Entry<T>) => (map: Map<T>) => Map<T>} */
|
|
41
41
|
const setUpdateEntry = o => entry => btreeSet(keyCmp(entry[0]))(old => old === undefined ? entry : [old[0], o(old[1])(entry[1])])
|
|
42
42
|
|
|
43
|
-
/** @type {<T>(o: operator.
|
|
44
|
-
const
|
|
43
|
+
/** @type {<T>(o: operator.Reduce<T>) => (name: string) => (value: T) => (map: Map<T>) => Map<T>} */
|
|
44
|
+
const setReduce = o => name => value => setUpdateEntry(o)([name, value])
|
|
45
45
|
|
|
46
46
|
/** @type {(name: string) => <T>(value: T) => (map: Map<T>) => Map<T>} */
|
|
47
47
|
const setReplace = name => value => setUpdateEntry(replace)([name, value])
|
|
@@ -53,7 +53,7 @@ const entries = values
|
|
|
53
53
|
const replace = () => b => b
|
|
54
54
|
|
|
55
55
|
/** @type {<T>(entries: list.List<Entry<T>>) => Map<T>} */
|
|
56
|
-
const fromEntries =
|
|
56
|
+
const fromEntries = fold(setUpdateEntry(replace))(undefined)
|
|
57
57
|
|
|
58
58
|
/** @type {(name: string) => <T>(map: Map<T>) => Map<T>} */
|
|
59
59
|
const remove = name => btreeRemove(keyCmp(name))
|
|
@@ -64,7 +64,7 @@ module.exports = {
|
|
|
64
64
|
/** @readonly */
|
|
65
65
|
at,
|
|
66
66
|
/** @readonly */
|
|
67
|
-
|
|
67
|
+
setReduce,
|
|
68
68
|
/** @readonly */
|
|
69
69
|
setReplace,
|
|
70
70
|
/** @readonly */
|
package/types/map/test.f.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const { at, setReplace,
|
|
1
|
+
const { at, setReplace, setReduce, empty, entries, remove } = require('./module.f.cjs')
|
|
2
2
|
const seq = require('../list/module.f.cjs')
|
|
3
3
|
|
|
4
4
|
{
|
|
@@ -41,7 +41,7 @@ const seq = require('../list/module.f.cjs')
|
|
|
41
41
|
m = remove('Hello world!')(m)
|
|
42
42
|
if (at('Hello world!')(m) !== undefined) { throw m }
|
|
43
43
|
|
|
44
|
-
m =
|
|
44
|
+
m = setReduce(a => b => a + b)('a')(43)(m)
|
|
45
45
|
if (at('a')(m) !== 44) { throw 'error' }
|
|
46
46
|
}
|
|
47
47
|
|
package/types/module.f.cjs
CHANGED
|
@@ -16,7 +16,7 @@ module.exports = {
|
|
|
16
16
|
/** @readonly */
|
|
17
17
|
result: require('./result/module.f.cjs'),
|
|
18
18
|
/** @readonly */
|
|
19
|
-
|
|
19
|
+
stringset: require('./stringset/module.f.cjs'),
|
|
20
20
|
/** @readonly */
|
|
21
21
|
bigint: require('./bigint/module.f.cjs'),
|
|
22
22
|
/** @readonly */
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
const {
|
|
1
|
+
const { reduce } = require('../list/module.f.cjs')
|
|
2
2
|
const { addition, min: minOp, max: maxOp } = require('../function/operator/module.f.cjs')
|
|
3
3
|
const compare = require('../function/compare/module.f.cjs')
|
|
4
4
|
const { unsafeCmp } = compare
|
|
5
5
|
|
|
6
|
-
const sum =
|
|
6
|
+
const sum = reduce(addition)(0)
|
|
7
7
|
|
|
8
|
-
const min =
|
|
8
|
+
const min = reduce(minOp)(undefined)
|
|
9
9
|
|
|
10
|
-
const max =
|
|
10
|
+
const max = reduce(maxOp)(undefined)
|
|
11
11
|
|
|
12
12
|
/** @type {(a: number) => (b: number) => compare.Sign} */
|
|
13
13
|
const cmp = unsafeCmp
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
const list = require('../list/module.f.cjs')
|
|
2
|
-
const {
|
|
2
|
+
const { reduce: listReduce, repeat: listRepeat } = list
|
|
3
3
|
const { compose } = require('../function/module.f.cjs')
|
|
4
4
|
const compare = require('../function/compare/module.f.cjs')
|
|
5
5
|
const { unsafeCmp } = compare
|
|
6
6
|
const op = require('../function/operator/module.f.cjs')
|
|
7
7
|
const { join: joinOp, concat: concatOp } = op
|
|
8
8
|
|
|
9
|
-
/** @type {(o: op.
|
|
10
|
-
const
|
|
9
|
+
/** @type {(o: op.Reduce<string>) => (input: list.List<string>) => string} */
|
|
10
|
+
const reduce = o => listReduce(o)('')
|
|
11
11
|
|
|
12
|
-
const join = compose(joinOp)(
|
|
12
|
+
const join = compose(joinOp)(reduce)
|
|
13
13
|
|
|
14
|
-
const concat =
|
|
14
|
+
const concat = reduce(concatOp)
|
|
15
15
|
|
|
16
16
|
/** @type {(n: string) => (v: number) => string} */
|
|
17
17
|
const repeat = v => compose(listRepeat(v))(concat)
|
|
@@ -9,18 +9,21 @@ const {
|
|
|
9
9
|
} = btree
|
|
10
10
|
const { cmp } = require("../string/module.f.cjs")
|
|
11
11
|
const list = require('../list/module.f.cjs')
|
|
12
|
-
const {
|
|
12
|
+
const { fold } = list
|
|
13
13
|
const { compose } = require('../function/module.f.cjs')
|
|
14
14
|
|
|
15
15
|
/** @typedef {btTypes.Tree<string>} StringSet */
|
|
16
16
|
|
|
17
17
|
/** @type {(value: string) => (set: StringSet) => boolean} */
|
|
18
|
-
const contains = value =>
|
|
18
|
+
const contains = value => {
|
|
19
|
+
const f = find(cmp(value))
|
|
20
|
+
return s => s !== undefined && isFound(f(s).first)
|
|
21
|
+
}
|
|
19
22
|
|
|
20
23
|
/** @type {(value: string) => (s: StringSet) => StringSet} */
|
|
21
24
|
const set = value => btreeSet(cmp(value))(() => value)
|
|
22
25
|
|
|
23
|
-
const fromValues =
|
|
26
|
+
const fromValues = fold(set)(undefined)
|
|
24
27
|
|
|
25
28
|
/** @type {(value: string) => (s: StringSet) => StringSet} */
|
|
26
29
|
const remove = compose(cmp)(btreeRemove)
|
|
File without changes
|