functionalscript 0.0.191 → 0.0.194
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/cmp/index.js +2 -2
- package/function/index.js +0 -5
- package/json/index.js +26 -10
- package/json/test.js +4 -2
- package/map/index.js +9 -3
- package/module-manager/index.js +3 -3
- package/package.json +1 -1
- package/sequence/array/index.js +3 -4
- package/sequence/asyncIterable/index.js +2 -2
- package/sequence/index.js +4 -3
- package/sequence/iterable/index.js +2 -2
- package/sequence/iterable/test.js +3 -3
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 cmpV0 = cmp(v0)
|
|
22
|
+
return /** @type {Index5} */ (cmpV0 <= 0 ? cmpV0 + 1 : cmp(v1) + 3)
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
/** @type {(a: string) => (b: string) => Sign} */
|
package/function/index.js
CHANGED
|
@@ -7,9 +7,6 @@
|
|
|
7
7
|
/** @type {<X, O>(f: Func<X, O>) => <I>(g: Func<I, X>) => Func<I, O>} */
|
|
8
8
|
const combine = f => g => x => f(g(x))
|
|
9
9
|
|
|
10
|
-
/** @type {<I, X>(g: Func<I, X>) => <O>(g: Func<X, O>) => Func<I, O>} */
|
|
11
|
-
const pipe = g => f => x => f(g(x))
|
|
12
|
-
|
|
13
10
|
/** @type {<T>(value: T) => T} */
|
|
14
11
|
const id = value => value
|
|
15
12
|
|
|
@@ -17,7 +14,5 @@ module.exports = {
|
|
|
17
14
|
/** @readonly */
|
|
18
15
|
id,
|
|
19
16
|
/** @readonly */
|
|
20
|
-
pipe,
|
|
21
|
-
/** @readonly */
|
|
22
17
|
combine,
|
|
23
18
|
}
|
package/json/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
const seq = require('../sequence')
|
|
2
2
|
const map = require('../map')
|
|
3
3
|
const op = require('../sequence/operator')
|
|
4
|
+
const option = require('../option')
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* @typedef {{
|
|
@@ -25,17 +26,25 @@ const addProperty = value => {
|
|
|
25
26
|
return path => f(seq.fromArray(path))
|
|
26
27
|
}
|
|
27
28
|
|
|
28
|
-
/** @type {(kv: readonly[string,
|
|
29
|
-
const property = ([k, v]) => seq.concat(
|
|
29
|
+
/** @type {(kv: readonly[string, Json]) => seq.Sequence<string>} */
|
|
30
|
+
const property = ([k, v]) => seq.concat(
|
|
31
|
+
seq.list(JSON.stringify(k)),
|
|
32
|
+
seq.list(':'),
|
|
33
|
+
stringSequence(v))
|
|
34
|
+
|
|
35
|
+
const comma = seq.list(',')
|
|
30
36
|
|
|
31
37
|
/** @type {op.Scan<seq.Sequence<string>, seq.Sequence<string>>} */
|
|
32
|
-
const commaValue = a => [seq.concat(
|
|
38
|
+
const commaValue = a => [seq.concat(comma, a), commaValue]
|
|
33
39
|
|
|
34
40
|
/** @type {op.Scan<seq.Sequence<string>, seq.Sequence<string>>} */
|
|
35
41
|
const joinScan = value => [value, commaValue]
|
|
36
42
|
|
|
37
43
|
/** @type {seq.SequenceMap<seq.Sequence<string>, string>} */
|
|
38
|
-
const join = input =>
|
|
44
|
+
const join = input => {
|
|
45
|
+
const _0 = seq.scan(joinScan)(input)
|
|
46
|
+
return seq.flat(_0)
|
|
47
|
+
}
|
|
39
48
|
|
|
40
49
|
/** @type {(open: string) => (close: string) => (input: seq.Sequence<seq.Sequence<string>>) => seq.Sequence<string>} */
|
|
41
50
|
const list = open => close => {
|
|
@@ -50,16 +59,23 @@ const arrayList = list('[')(']')
|
|
|
50
59
|
|
|
51
60
|
/** @type {(object: Object) => seq.Sequence<string>} */
|
|
52
61
|
const objectStringify = object => {
|
|
53
|
-
|
|
54
|
-
const
|
|
55
|
-
|
|
62
|
+
const _0 = Object.entries(object)
|
|
63
|
+
const _1 = seq.fromArray(_0)
|
|
64
|
+
const _2 = map.fromEntries(_1)
|
|
65
|
+
const _3 = _2.entries
|
|
66
|
+
const _4 = seq.map(property)(_3)
|
|
67
|
+
return objectList(_4)
|
|
56
68
|
}
|
|
57
69
|
|
|
58
70
|
/** @type {(array: Array) => seq.Sequence<string>} */
|
|
59
|
-
const arrayStringify = array =>
|
|
71
|
+
const arrayStringify = array => {
|
|
72
|
+
const _0 = seq.fromArray(array)
|
|
73
|
+
const _1 = seq.map(stringSequence)(_0)
|
|
74
|
+
return arrayList(_1)
|
|
75
|
+
}
|
|
60
76
|
|
|
61
77
|
/** @type {(value: Json) => seq.Sequence<string>} */
|
|
62
|
-
const
|
|
78
|
+
const stringSequence = value => {
|
|
63
79
|
const x = typeof value
|
|
64
80
|
switch (typeof value) {
|
|
65
81
|
case 'boolean': { return seq.list(value ? "true" : "false") }
|
|
@@ -79,7 +95,7 @@ const stringSeq = value => {
|
|
|
79
95
|
*
|
|
80
96
|
* @type {(value: Json) => string}
|
|
81
97
|
*/
|
|
82
|
-
const stringify = value => seq.join('')(
|
|
98
|
+
const stringify = value => seq.join('')(stringSequence(value))
|
|
83
99
|
|
|
84
100
|
module.exports = {
|
|
85
101
|
/** @readonly */
|
package/json/test.js
CHANGED
|
@@ -13,6 +13,8 @@ if (json.addProperty("Hello")([])({}) !== "Hello") { throw 'error' }
|
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
{
|
|
16
|
-
const
|
|
17
|
-
|
|
16
|
+
const _0 = { a: { y: [24] }, c: [], b: 12 }
|
|
17
|
+
const _1 = json.addProperty("Hello")(['a', 'x'])(_0)
|
|
18
|
+
const _2 = json.stringify(_1)
|
|
19
|
+
if (_2 !== '{"a":{"x":"Hello","y":[24]},"b":12,"c":[]}') { throw _2 }
|
|
18
20
|
}
|
package/map/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const option = require("../option")
|
|
2
|
-
const { getVisitor, setVisitor, values
|
|
2
|
+
const { getVisitor, setVisitor, values } = require("../btree")
|
|
3
3
|
const { cmp } = require("../cmp")
|
|
4
4
|
const seq = require("../sequence")
|
|
5
5
|
const op = require("../sequence/operator")
|
|
@@ -48,7 +48,7 @@ const create = root => ({
|
|
|
48
48
|
if ('overflow' in result) { return create(result.overflow) }
|
|
49
49
|
throw ''
|
|
50
50
|
},
|
|
51
|
-
entries:
|
|
51
|
+
entries: values(root),
|
|
52
52
|
root,
|
|
53
53
|
})
|
|
54
54
|
|
|
@@ -67,8 +67,14 @@ const empty = {
|
|
|
67
67
|
root: undefined
|
|
68
68
|
}
|
|
69
69
|
|
|
70
|
+
/** @type {<T>(map: Map<T>) => (entry: Entry<T>) => Map<T>} */
|
|
71
|
+
const setOperator = map => ([k, v]) => map.set(k)(v)
|
|
72
|
+
|
|
70
73
|
/** @type {<T>(entries: seq.Sequence<Entry<T>>) => Map<T>} */
|
|
71
|
-
const fromEntries =
|
|
74
|
+
const fromEntries = entries => {
|
|
75
|
+
/** @typedef {typeof entries extends seq.Sequence<Entry<infer T>> ? T : never} T */
|
|
76
|
+
return seq.fold(setOperator)(/** @type {Map<T>} */(empty))(entries)
|
|
77
|
+
}
|
|
72
78
|
|
|
73
79
|
module.exports = {
|
|
74
80
|
/** @readonly */
|
package/module-manager/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const array = require('../sequence/array')
|
|
2
|
-
const {
|
|
2
|
+
const { combine } = require('../function')
|
|
3
3
|
const option = require('../option')
|
|
4
4
|
const { head, last, splitLast, splitFirst } = array
|
|
5
5
|
const iter = require('../sequence/iterable')
|
|
@@ -88,9 +88,9 @@ const external = packages => {
|
|
|
88
88
|
const defined = ([first, tail]) => externalOrInternal(packages(first))(tail)
|
|
89
89
|
/** @type {(_: Path) => readonly [string, Path]|undefined} */
|
|
90
90
|
const sf = splitFirst
|
|
91
|
-
return
|
|
92
|
-
(sf)
|
|
91
|
+
return combine
|
|
93
92
|
(option.map(defined))
|
|
93
|
+
(sf)
|
|
94
94
|
}
|
|
95
95
|
|
|
96
96
|
/** @type {(_: Location) => (_: string) => Module|undefined} */
|
package/package.json
CHANGED
package/sequence/array/index.js
CHANGED
|
@@ -86,10 +86,9 @@ const head = a => a.length === 0 ? undefined : uncheckHead(a)
|
|
|
86
86
|
|
|
87
87
|
/** @type {<T>(_: Array<T>) => readonly [Array<T>, T]|undefined} */
|
|
88
88
|
const splitLast = a => {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
return option.map(split)(last(a))
|
|
89
|
+
const lastA = last(a)
|
|
90
|
+
if (lastA === undefined) { return undefined }
|
|
91
|
+
return [uncheckHead(a), lastA]
|
|
93
92
|
}
|
|
94
93
|
|
|
95
94
|
/** @type {(index: number) => <T>(a: Array<T>) => readonly[T]|undefined} */
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const {
|
|
1
|
+
const { combine } = require('../../function')
|
|
2
2
|
const seq = require('../operator')
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -69,7 +69,7 @@ const reduce = ([first, s]) => async c => {
|
|
|
69
69
|
|
|
70
70
|
const sum = reduce(seq.sum)
|
|
71
71
|
|
|
72
|
-
const join =
|
|
72
|
+
const join = combine(reduce)(seq.join)
|
|
73
73
|
|
|
74
74
|
const length = reduce(seq.length)
|
|
75
75
|
|
package/sequence/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const array = require('./array')
|
|
2
2
|
const seqOp = require('./operator')
|
|
3
|
-
const {
|
|
3
|
+
const { combine } = require('../function')
|
|
4
4
|
const op = require('../function/operator')
|
|
5
5
|
const { logicalNot, strictEqual } = require('../function/operator')
|
|
6
6
|
|
|
@@ -202,7 +202,8 @@ const sum = reduce(seqOp.sum)
|
|
|
202
202
|
|
|
203
203
|
const length = reduce(seqOp.length)
|
|
204
204
|
|
|
205
|
-
|
|
205
|
+
/** @type {(separator: string) => SequenceReduce<string, string>} */
|
|
206
|
+
const join = separator => reduce(seqOp.join(separator))
|
|
206
207
|
|
|
207
208
|
/** @type {<T>(f: (value: T) => boolean) => SequenceMap<T, T>} */
|
|
208
209
|
const takeWhile = f => input => () => {
|
|
@@ -236,7 +237,7 @@ const some = f => input => find(x => x)(map(f)(input)) !== undefined
|
|
|
236
237
|
const includes = value => some(strictEqual(value))
|
|
237
238
|
|
|
238
239
|
/** @type {<T>(f: (value: T) => boolean) => SequenceReduce<T, boolean>} */
|
|
239
|
-
const every = f => input => !some(
|
|
240
|
+
const every = f => input => !some(combine(logicalNot)(f))(input)
|
|
240
241
|
|
|
241
242
|
/** @type {<T>(list: Sequence<T>) => Iterable<T>} */
|
|
242
243
|
const iterable = list => ({
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const {
|
|
1
|
+
const { combine } = require('../../function')
|
|
2
2
|
const seq = require('../operator')
|
|
3
3
|
|
|
4
4
|
/** @type {<T>(a: Iterable<T>) => (b: Iterable<T>) => Iterable<T>} */
|
|
@@ -39,7 +39,7 @@ const sum = reduce(seq.sum)
|
|
|
39
39
|
|
|
40
40
|
const length = reduce(seq.length)
|
|
41
41
|
|
|
42
|
-
const join =
|
|
42
|
+
const join = combine(reduce)(seq.join)
|
|
43
43
|
|
|
44
44
|
/** @type {<T, R>(f: (value: T) => Iterable<R>) => (c: Iterable<T>) => Iterable<R>} */
|
|
45
45
|
const flatMap = f => c => ({
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const i = require('.')
|
|
2
|
-
const {
|
|
2
|
+
const { combine } = require('../../function')
|
|
3
3
|
|
|
4
4
|
{
|
|
5
5
|
const r = i.sum([120, 300, 42])
|
|
@@ -33,9 +33,9 @@ const { pipe } = require('../../function')
|
|
|
33
33
|
/** @type {(_: string) => string|undefined} */
|
|
34
34
|
const file = _ => 'x'
|
|
35
35
|
/** @type {(_: string) => string|undefined} */
|
|
36
|
-
const x = p =>
|
|
37
|
-
(i.map(x => file(x())))
|
|
36
|
+
const x = p => combine
|
|
38
37
|
(i.find(x => x !== undefined))
|
|
38
|
+
(i.map(x => file(x())))
|
|
39
39
|
([() => p, () => `${p}.js`, () => `${p}/index.js`])
|
|
40
40
|
if (x('index.js') !== 'x') { throw 'error' }
|
|
41
41
|
}
|