functionalscript 0.0.166 → 0.0.167
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/async/iterable/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
const { pipe } = require('../../
|
|
2
|
-
const
|
|
1
|
+
const { pipe } = require('../../function')
|
|
2
|
+
const seq = require('../../sequence')
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* @template T
|
|
@@ -14,10 +14,10 @@ const mr = require('../../map-reduce')
|
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
16
|
* @template T
|
|
17
|
-
* @typedef {Iterable<T> | AsyncIterable<T>}
|
|
17
|
+
* @typedef {Iterable<T> | AsyncIterable<T>} AnyIterable
|
|
18
18
|
*/
|
|
19
19
|
|
|
20
|
-
/** @type {<T, R>(f: (value: T) => PromiseOrValue<R>) => (c:
|
|
20
|
+
/** @type {<T, R>(f: (value: T) => PromiseOrValue<R>) => (c: AnyIterable<T>) => AsyncIterable<R>} */
|
|
21
21
|
const map = f => c => ({
|
|
22
22
|
async *[Symbol.asyncIterator]() {
|
|
23
23
|
for await (const i of c) {
|
|
@@ -26,7 +26,7 @@ const map = f => c => ({
|
|
|
26
26
|
}
|
|
27
27
|
})
|
|
28
28
|
|
|
29
|
-
/** @type {<T>(c:
|
|
29
|
+
/** @type {<T>(c: AnyIterable<AnyIterable<T>>) => AsyncIterable<T>} */
|
|
30
30
|
const flatten = c => ({
|
|
31
31
|
async *[Symbol.asyncIterator]() {
|
|
32
32
|
for await (const i of c) {
|
|
@@ -35,7 +35,7 @@ const flatten = c => ({
|
|
|
35
35
|
}
|
|
36
36
|
})
|
|
37
37
|
|
|
38
|
-
/** @type {<T>(f: (value: T) => Promise<boolean>) => (c:
|
|
38
|
+
/** @type {<T>(f: (value: T) => Promise<boolean>) => (c: AnyIterable<T>) => AnyIterable<T>} */
|
|
39
39
|
const filter = f => c => ({
|
|
40
40
|
async *[Symbol.asyncIterator]() {
|
|
41
41
|
for await (const i of c) {
|
|
@@ -46,7 +46,7 @@ const filter = f => c => ({
|
|
|
46
46
|
}
|
|
47
47
|
})
|
|
48
48
|
|
|
49
|
-
/** @type {<T, R>(f: (value: T) =>
|
|
49
|
+
/** @type {<T, R>(f: (value: T) => AnyIterable<R>) => (c: AnyIterable<T>) => AsyncIterable<R>} */
|
|
50
50
|
const flatMap = f => pipe(map(f))(flatten)
|
|
51
51
|
|
|
52
52
|
/**
|
|
@@ -55,7 +55,7 @@ const flatMap = f => pipe(map(f))(flatten)
|
|
|
55
55
|
* @typedef {(accumulator: A) => (value: T) => PromiseOrValue<A>} Merge
|
|
56
56
|
*/
|
|
57
57
|
|
|
58
|
-
/** @type {<A, T>(merge: Merge<A, T>) => (init: A) => (c:
|
|
58
|
+
/** @type {<A, T>(merge: Merge<A, T>) => (init: A) => (c: AnyIterable<T>) => Promise<A>} */
|
|
59
59
|
const reduce = merge => init => async c => {
|
|
60
60
|
let result = init
|
|
61
61
|
for await (const i of c) {
|
|
@@ -64,7 +64,7 @@ const reduce = merge => init => async c => {
|
|
|
64
64
|
return result
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
-
/** @type {<T>(a:
|
|
67
|
+
/** @type {<T>(a: AnyIterable<T>) => (b: AnyIterable<T>) => AsyncIterable<T>} */
|
|
68
68
|
const concat = a => b => ({
|
|
69
69
|
async *[Symbol.asyncIterator]() {
|
|
70
70
|
yield* a
|
|
@@ -72,7 +72,7 @@ const concat = a => b => ({
|
|
|
72
72
|
}
|
|
73
73
|
})
|
|
74
74
|
|
|
75
|
-
/** @type {<A, T>(merg: Merge<A, T>) => (init: A) => (c:
|
|
75
|
+
/** @type {<A, T>(merg: Merge<A, T>) => (init: A) => (c: AnyIterable<T>) => AsyncIterable<A>} */
|
|
76
76
|
const exclusiveScan = merge => init => c => ({
|
|
77
77
|
async *[Symbol.asyncIterator]() {
|
|
78
78
|
let result = init
|
|
@@ -83,17 +83,29 @@ const exclusiveScan = merge => init => c => ({
|
|
|
83
83
|
}
|
|
84
84
|
})
|
|
85
85
|
|
|
86
|
-
/** @type {<
|
|
86
|
+
/** @type {<T, R>(es: seq.ExlusiveScan<T, R>) => (c: AnyIterable<T>) => AsyncIterable<R>} */
|
|
87
|
+
const applyExclusiveScan = es => c => ({
|
|
88
|
+
async *[Symbol.asyncIterator]() {
|
|
89
|
+
let ies = es
|
|
90
|
+
for await (const i of c) {
|
|
91
|
+
const result = ies(i)
|
|
92
|
+
ies = result[1]
|
|
93
|
+
yield result[0]
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
})
|
|
97
|
+
|
|
98
|
+
/** @type {<A, T>(merge: Merge<A, T>) => (init: A) => (c: AnyIterable<T>) => AsyncIterable<A>} */
|
|
87
99
|
const inclusiveScan = merge => init => c => concat([init])(exclusiveScan(merge)(init)(c))
|
|
88
100
|
|
|
89
|
-
/** @type {<I, S, R>(op:
|
|
101
|
+
/** @type {<I, S, R>(op: seq.Operation<I, S, R>) => (_: AnyIterable<I>) => Promise<R>} */
|
|
90
102
|
const apply = ({ merge, init, result }) => async c => result(await reduce(merge)(init)(c))
|
|
91
103
|
|
|
92
|
-
const sum = apply(
|
|
104
|
+
const sum = apply(seq.sum)
|
|
93
105
|
|
|
94
|
-
const join = pipe(
|
|
106
|
+
const join = pipe(seq.join)(apply)
|
|
95
107
|
|
|
96
|
-
const size = apply(
|
|
108
|
+
const size = apply(seq.size)
|
|
97
109
|
|
|
98
110
|
module.exports = {
|
|
99
111
|
/** @readonly */
|
|
File without changes
|
package/iterable/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
const { pipe } = require('../
|
|
2
|
-
const
|
|
1
|
+
const { pipe } = require('../function')
|
|
2
|
+
const seq = require('../sequence')
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* @template S
|
|
@@ -38,7 +38,7 @@ const exclusiveScan = merge => init => c => ({
|
|
|
38
38
|
/** @type {<A, T>(merge: Merge<A, T>) => (init: A) => (c: Iterable<T>) => Iterable<A>} */
|
|
39
39
|
const inclusiveScan = merge => init => c => concat([init])(exclusiveScan(merge)(init)(c))
|
|
40
40
|
|
|
41
|
-
/** @type {<T, R>(es:
|
|
41
|
+
/** @type {<T, R>(es: seq.ExlusiveScan<T, R>) => (c: Iterable<T>) => Iterable<R>} */
|
|
42
42
|
const applyExclusiveScan = es => c => ({
|
|
43
43
|
*[Symbol.iterator]() {
|
|
44
44
|
let ies = es
|
|
@@ -50,16 +50,16 @@ const applyExclusiveScan = es => c => ({
|
|
|
50
50
|
}
|
|
51
51
|
})
|
|
52
52
|
|
|
53
|
-
const entries = applyExclusiveScan(
|
|
53
|
+
const entries = applyExclusiveScan(seq.entries)
|
|
54
54
|
|
|
55
|
-
/** @type {<I, S, R>(op:
|
|
55
|
+
/** @type {<I, S, R>(op: seq.Operation<I, S, R>) => (_: Iterable<I>) => R} */
|
|
56
56
|
const apply = ({ merge, init, result }) => pipe(reduce(merge)(init))(result)
|
|
57
57
|
|
|
58
|
-
const sum = apply(
|
|
58
|
+
const sum = apply(seq.sum)
|
|
59
59
|
|
|
60
|
-
const size = apply(
|
|
60
|
+
const size = apply(seq.size)
|
|
61
61
|
|
|
62
|
-
const join = pipe(
|
|
62
|
+
const join = pipe(seq.join)(apply)
|
|
63
63
|
|
|
64
64
|
/** @type {<T, R>(f: (value: T) => R) => (c: Iterable<T>) => Iterable<R>} */
|
|
65
65
|
const map = f => c => ({
|
package/iterable/test.js
CHANGED
package/module-manager/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const array = require('../array')
|
|
2
|
-
const { pipe } = require('../
|
|
2
|
+
const { pipe } = require('../function')
|
|
3
3
|
const option = require('../option')
|
|
4
4
|
const { head, last, splitLast, splitFirst } = array
|
|
5
5
|
const iter = require('../iterable')
|
|
@@ -38,7 +38,7 @@ const iter = require('../iterable')
|
|
|
38
38
|
|
|
39
39
|
/** @typedef {(_: string) => undefined|Package|Dependencies} Dependencies */
|
|
40
40
|
|
|
41
|
-
/** @type {import('../
|
|
41
|
+
/** @type {import('../sequence').Operation<string, undefined|Path, undefined|Path>} */
|
|
42
42
|
const pathNormReduce = {
|
|
43
43
|
merge: path => item =>
|
|
44
44
|
path === undefined ?
|
package/package.json
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const { pipe, id } = require('../
|
|
1
|
+
const { pipe, id } = require('../function')
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* @template S
|
|
@@ -57,6 +57,16 @@ const size = {
|
|
|
57
57
|
* @typedef {(value: T) => readonly [R, ExlusiveScan<T, R>]} ExlusiveScan
|
|
58
58
|
*/
|
|
59
59
|
|
|
60
|
+
/**
|
|
61
|
+
* @template T
|
|
62
|
+
* @template R
|
|
63
|
+
* @template I
|
|
64
|
+
* @typedef {{
|
|
65
|
+
* readonly exlusive: ExlusiveScan<T, R>
|
|
66
|
+
* readonly default: I
|
|
67
|
+
* }} InclusiveScan
|
|
68
|
+
*/
|
|
69
|
+
|
|
60
70
|
/**
|
|
61
71
|
* @template T
|
|
62
72
|
* @typedef {readonly[number, T]} Entry
|