functionalscript 0.0.194 → 0.0.197
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/btree/index.js +2 -2
- package/btree/test.js +9 -9
- package/cmp/index.js +2 -2
- package/json/index.js +6 -5
- package/map/index.js +3 -3
- package/package.json +1 -1
- package/sequence/array/index.js +15 -0
- package/sequence/index.js +2 -17
- package/sequence/iterable/index.js +1 -0
- package/sequence/test.js +6 -5
package/btree/index.js
CHANGED
|
@@ -339,8 +339,8 @@ module.exports = {
|
|
|
339
339
|
* @type { <T>(cmp: Cmp<T>) => (node: Node<T>) => T|undefined }
|
|
340
340
|
*/
|
|
341
341
|
getVisitor: cmp => node => {
|
|
342
|
-
const
|
|
343
|
-
if ('done' in
|
|
342
|
+
const _0 = visit(getVisitor)(cmp)(() => { throw '' })(node)
|
|
343
|
+
if ('done' in _0 && _0.done) { return _0.value }
|
|
344
344
|
return undefined
|
|
345
345
|
},
|
|
346
346
|
/** @readonly */
|
package/btree/test.js
CHANGED
|
@@ -13,18 +13,18 @@ const set = node => value => {
|
|
|
13
13
|
|
|
14
14
|
const test = () => {
|
|
15
15
|
/** @type {btree.Node<string>} */
|
|
16
|
-
let
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
16
|
+
let _map = ['a']
|
|
17
|
+
_map = set(_map)('b')
|
|
18
|
+
_map = set(_map)('c')
|
|
19
|
+
_map = set(_map)('d')
|
|
20
|
+
_map = set(_map)('e')
|
|
21
|
+
_map = set(_map)('f')
|
|
22
22
|
//
|
|
23
23
|
{
|
|
24
24
|
/** @type {import('../sequence').Result<string>} */
|
|
25
|
-
let
|
|
26
|
-
while (
|
|
27
|
-
|
|
25
|
+
let _item = list.next(valuesList(_map))
|
|
26
|
+
while (_item !== undefined) {
|
|
27
|
+
_item = list.next(_item[1])
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
30
|
}
|
package/cmp/index.js
CHANGED
|
@@ -18,8 +18,8 @@ const index3 = cmp => value => /** @type {Index3} */ (cmp(value) + 1)
|
|
|
18
18
|
|
|
19
19
|
/** @type {<T>(cmp: Cmp<T>) => (v2: Array2<T>) => Index5} */
|
|
20
20
|
const index5 = cmp => ([v0, v1]) => {
|
|
21
|
-
const
|
|
22
|
-
return /** @type {Index5} */ (
|
|
21
|
+
const _0 = cmp(v0)
|
|
22
|
+
return /** @type {Index5} */ (_0 <= 0 ? _0 + 1 : cmp(v1) + 3)
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
/** @type {(a: string) => (b: string) => Sign} */
|
package/json/index.js
CHANGED
|
@@ -2,6 +2,7 @@ const seq = require('../sequence')
|
|
|
2
2
|
const map = require('../map')
|
|
3
3
|
const op = require('../sequence/operator')
|
|
4
4
|
const option = require('../option')
|
|
5
|
+
const array = require('../sequence/array')
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* @typedef {{
|
|
@@ -23,7 +24,7 @@ const addProperty = value => {
|
|
|
23
24
|
const [name, tail] = result
|
|
24
25
|
return { ...srcObject, [name]: f(tail)(srcObject[name]) }
|
|
25
26
|
}
|
|
26
|
-
return path => f(
|
|
27
|
+
return path => f(array.sequence(path))
|
|
27
28
|
}
|
|
28
29
|
|
|
29
30
|
/** @type {(kv: readonly[string, Json]) => seq.Sequence<string>} */
|
|
@@ -60,16 +61,16 @@ const arrayList = list('[')(']')
|
|
|
60
61
|
/** @type {(object: Object) => seq.Sequence<string>} */
|
|
61
62
|
const objectStringify = object => {
|
|
62
63
|
const _0 = Object.entries(object)
|
|
63
|
-
const _1 =
|
|
64
|
+
const _1 = array.sequence(_0)
|
|
64
65
|
const _2 = map.fromEntries(_1)
|
|
65
66
|
const _3 = _2.entries
|
|
66
67
|
const _4 = seq.map(property)(_3)
|
|
67
68
|
return objectList(_4)
|
|
68
69
|
}
|
|
69
70
|
|
|
70
|
-
/** @type {(
|
|
71
|
-
const arrayStringify =
|
|
72
|
-
const _0 =
|
|
71
|
+
/** @type {(input: Array) => seq.Sequence<string>} */
|
|
72
|
+
const arrayStringify = input => {
|
|
73
|
+
const _0 = array.sequence(input)
|
|
73
74
|
const _1 = seq.map(stringSequence)(_0)
|
|
74
75
|
return arrayList(_1)
|
|
75
76
|
}
|
package/map/index.js
CHANGED
|
@@ -43,9 +43,9 @@ const keyCmp = a => ([b]) => cmp(a)(b)
|
|
|
43
43
|
const create = root => ({
|
|
44
44
|
get: name => option.map(([,value]) => value)(getVisitor(keyCmp(name))(root)),
|
|
45
45
|
set: name => value => {
|
|
46
|
-
const
|
|
47
|
-
if ('replace' in
|
|
48
|
-
if ('overflow' in
|
|
46
|
+
const _0 = setVisitor(keyCmp(name))(() => [name, value])(root)
|
|
47
|
+
if ('replace' in _0) { return create(_0.replace) }
|
|
48
|
+
if ('overflow' in _0) { return create(_0.overflow) }
|
|
49
49
|
throw ''
|
|
50
50
|
},
|
|
51
51
|
entries: values(root),
|
package/package.json
CHANGED
package/sequence/array/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
const option = require('../../option')
|
|
2
|
+
const seq = require('..')
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* @template T
|
|
@@ -94,6 +95,18 @@ const splitLast = a => {
|
|
|
94
95
|
/** @type {(index: number) => <T>(a: Array<T>) => readonly[T]|undefined} */
|
|
95
96
|
const at = index => a => index < a.length ? [a[index]] : undefined
|
|
96
97
|
|
|
98
|
+
/** @type {<T>(array: Array<T>) => seq.Sequence<T>} */
|
|
99
|
+
const sequence = a => {
|
|
100
|
+
/** @typedef {typeof a extends Array<infer T> ? T : never} T */
|
|
101
|
+
/** @type {(index: number) => seq.Sequence<T>} */
|
|
102
|
+
const seq = index => () => {
|
|
103
|
+
const result = at(index)(a)
|
|
104
|
+
if (result === undefined) { return undefined }
|
|
105
|
+
return [result[0], seq(index + 1)]
|
|
106
|
+
}
|
|
107
|
+
return seq(0)
|
|
108
|
+
}
|
|
109
|
+
|
|
97
110
|
module.exports = {
|
|
98
111
|
/** @readonly */
|
|
99
112
|
at,
|
|
@@ -109,4 +122,6 @@ module.exports = {
|
|
|
109
122
|
splitFirst,
|
|
110
123
|
/** @readonly */
|
|
111
124
|
splitLast,
|
|
125
|
+
/** @readonly */
|
|
126
|
+
sequence,
|
|
112
127
|
}
|
package/sequence/index.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
const array = require('./array')
|
|
2
1
|
const seqOp = require('./operator')
|
|
3
2
|
const { combine } = require('../function')
|
|
4
3
|
const op = require('../function/operator')
|
|
@@ -33,7 +32,7 @@ const { logicalNot, strictEqual } = require('../function/operator')
|
|
|
33
32
|
|
|
34
33
|
/**
|
|
35
34
|
* @template T
|
|
36
|
-
* @typedef {
|
|
35
|
+
* @typedef {readonly[T, Sequence<T>]} FirstAndTail
|
|
37
36
|
*/
|
|
38
37
|
|
|
39
38
|
const empty = () => undefined
|
|
@@ -93,18 +92,6 @@ const list = (...array) => {
|
|
|
93
92
|
}
|
|
94
93
|
}
|
|
95
94
|
|
|
96
|
-
/** @type {<T>(array: array.Array<T>) => Sequence<T>} */
|
|
97
|
-
const fromArray = a => {
|
|
98
|
-
/** @typedef {typeof a extends array.Array<infer T> ? T : never} T */
|
|
99
|
-
/** @type {(index: number) => Sequence<T>} */
|
|
100
|
-
const at = index => () => {
|
|
101
|
-
const result = array.at(index)(a)
|
|
102
|
-
if (result === undefined) { return undefined }
|
|
103
|
-
return [result[0], at(index + 1)]
|
|
104
|
-
}
|
|
105
|
-
return at(0)
|
|
106
|
-
}
|
|
107
|
-
|
|
108
95
|
/** @type {<T>(...array: readonly Sequence<T>[]) => Sequence<T>} */
|
|
109
96
|
const concat = (...array) => {
|
|
110
97
|
let i = array.length
|
|
@@ -265,7 +252,7 @@ const asyncIterable = list => ({
|
|
|
265
252
|
}
|
|
266
253
|
})
|
|
267
254
|
|
|
268
|
-
/** @type {<A>(a: Sequence<A>) => <B>(b: Sequence<B>) => Sequence<
|
|
255
|
+
/** @type {<A>(a: Sequence<A>) => <B>(b: Sequence<B>) => Sequence<readonly[A, B]>} */
|
|
269
256
|
const zip = a => b => () => {
|
|
270
257
|
const resultA = next(a)
|
|
271
258
|
if (resultA === undefined) { return undefined }
|
|
@@ -293,8 +280,6 @@ module.exports = {
|
|
|
293
280
|
/** @readonly */
|
|
294
281
|
first,
|
|
295
282
|
/** @readonly */
|
|
296
|
-
fromArray,
|
|
297
|
-
/** @readonly */
|
|
298
283
|
toArray,
|
|
299
284
|
/** @readonly */
|
|
300
285
|
iterable,
|
package/sequence/test.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
const seq = require('.')
|
|
2
2
|
const { sum } = require('./operator')
|
|
3
3
|
const op = require('./operator')
|
|
4
|
+
const array = require('./array')
|
|
4
5
|
|
|
5
6
|
/** @type {<T>(input: seq.Sequence<T>) => void} */
|
|
6
7
|
const print = input => {
|
|
@@ -14,9 +15,9 @@ const print = input => {
|
|
|
14
15
|
}
|
|
15
16
|
|
|
16
17
|
{
|
|
17
|
-
const big = seq.
|
|
18
|
-
const list0 = seq.
|
|
19
|
-
const list1 = seq.flatMap(x => seq.
|
|
18
|
+
const big = seq.list(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 42, 60)
|
|
19
|
+
const list0 = seq.list(0, 1, 2, 3)
|
|
20
|
+
const list1 = seq.flatMap(x => seq.list(x, x * 2, x * 3))(list0)
|
|
20
21
|
const list2 = seq.concat(list0, list0)
|
|
21
22
|
const list3 = seq.exclusiveScan(sum)(list0)
|
|
22
23
|
const r = seq.find(x => x === 42)(big)
|
|
@@ -27,7 +28,7 @@ const print = input => {
|
|
|
27
28
|
if (seq.first(seq.drop(16)(big)) !== 42) { throw 'drop'}
|
|
28
29
|
{
|
|
29
30
|
const a = seq.toArray(seq.generate(1_000_000))
|
|
30
|
-
let x = seq.concat(
|
|
31
|
+
let x = seq.concat(array.sequence(a), big)
|
|
31
32
|
const r = seq.next(x)
|
|
32
33
|
// print(x)
|
|
33
34
|
}
|
|
@@ -57,6 +58,6 @@ const print = input => {
|
|
|
57
58
|
}
|
|
58
59
|
|
|
59
60
|
{
|
|
60
|
-
const x = seq.join(':')(seq.
|
|
61
|
+
const x = seq.join(':')(seq.list("1", "2", "3", "4", "5", "6"))
|
|
61
62
|
if (x !== "1:2:3:4:5:6") { throw x }
|
|
62
63
|
}
|