functionalscript 0.0.163 → 0.0.164
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 +13 -8
- package/func/index.js +29 -1
- package/package.json +1 -1
package/async/iterable/index.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
const { todo } = require('../../dev')
|
|
2
1
|
const { pipe } = require('../../func')
|
|
3
2
|
const mapReduce = require('../../map-reduce')
|
|
4
3
|
|
|
@@ -7,6 +6,12 @@ const mapReduce = require('../../map-reduce')
|
|
|
7
6
|
* @typedef {Promise<T>|T} PromiseOrValue
|
|
8
7
|
*/
|
|
9
8
|
|
|
9
|
+
/**
|
|
10
|
+
* @template T
|
|
11
|
+
* @template R
|
|
12
|
+
* @typedef {(f: (value: T) => PromiseOrValue<R>) => (c: AsyncIterable<T>) => AsyncIterable<R>} Map
|
|
13
|
+
*/
|
|
14
|
+
|
|
10
15
|
/** @type {<T, R>(f: (value: T) => PromiseOrValue<R>) => (c: AsyncIterable<T>) => AsyncIterable<R>} */
|
|
11
16
|
const map = f => c => ({
|
|
12
17
|
async *[Symbol.asyncIterator]() {
|
|
@@ -45,7 +50,7 @@ const flatMap = f => pipe(map(f))(flatten)
|
|
|
45
50
|
* @typedef {(accumulator: A) => (value: T) => PromiseOrValue<A>} Merge
|
|
46
51
|
*/
|
|
47
52
|
|
|
48
|
-
/** @type {<A, T>(
|
|
53
|
+
/** @type {<A, T>(merge: Merge<A, T>) => (init: A) => (c: AsyncIterable<T>) => Promise<A>} */
|
|
49
54
|
const reduce = merge => init => async c => {
|
|
50
55
|
let result = init
|
|
51
56
|
for await (const i of c) {
|
|
@@ -54,20 +59,20 @@ const reduce = merge => init => async c => {
|
|
|
54
59
|
return result
|
|
55
60
|
}
|
|
56
61
|
|
|
57
|
-
/** @type {<A, T>(
|
|
58
|
-
const exclusiveScan =
|
|
62
|
+
/** @type {<A, T>(merg: Merge<A, T>) => (init: A) => (c: AsyncIterable<T>) => AsyncIterable<A>} */
|
|
63
|
+
const exclusiveScan = merge => init => c => ({
|
|
59
64
|
async *[Symbol.asyncIterator]() {
|
|
60
65
|
let result = init
|
|
61
66
|
for await (const i of c) {
|
|
62
|
-
result = await
|
|
67
|
+
result = await merge(result)(i)
|
|
63
68
|
yield result
|
|
64
69
|
}
|
|
65
70
|
}
|
|
66
71
|
})
|
|
67
72
|
|
|
68
|
-
/** @type {<A, T>(
|
|
69
|
-
const inclusiveScan =
|
|
70
|
-
const e = exclusiveScan(
|
|
73
|
+
/** @type {<A, T>(merge: Merge<A, T>) => (init: A) => (c: AsyncIterable<T>) => AsyncIterable<A>} */
|
|
74
|
+
const inclusiveScan = merge => init => {
|
|
75
|
+
const e = exclusiveScan(merge)(init)
|
|
71
76
|
return c => ({
|
|
72
77
|
async *[Symbol.asyncIterator]() {
|
|
73
78
|
yield init
|
package/func/index.js
CHANGED
|
@@ -1,12 +1,40 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/**
|
|
2
|
+
* @template I
|
|
3
|
+
* @template O
|
|
4
|
+
* @typedef {(_: I) => O} Func
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/** @type {<X, O>(f: Func<X, O>) => <I>(g: Func<I, X>) => Func<I, O>} */
|
|
8
|
+
const combine = f => g => x => f(g(x))
|
|
9
|
+
|
|
10
|
+
/** @type {<I, X>(g: Func<I, X>) => <O>(g: Func<X, O>) => Func<I, O>} */
|
|
2
11
|
const pipe = g => f => x => f(g(x))
|
|
3
12
|
|
|
4
13
|
/** @type {<T>(value: T) => T} */
|
|
5
14
|
const id = value => value
|
|
6
15
|
|
|
16
|
+
/**
|
|
17
|
+
* @template I
|
|
18
|
+
* @template O
|
|
19
|
+
* @typedef {{
|
|
20
|
+
* readonly pipe: <R>(f: Func<O, R>) => Pipe<I, R>
|
|
21
|
+
* readonly call: Func<I, O>
|
|
22
|
+
* }} Pipe
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
/** @type {<I, O>(f: Func<I, O>) => Pipe<I, O>} */
|
|
26
|
+
const pipex = call => ({
|
|
27
|
+
pipe: f => pipex(pipe(call)(f)),
|
|
28
|
+
call,
|
|
29
|
+
})
|
|
30
|
+
|
|
7
31
|
module.exports = {
|
|
8
32
|
/** @readonly */
|
|
9
33
|
id,
|
|
10
34
|
/** @readonly */
|
|
11
35
|
pipe,
|
|
36
|
+
/** @readonly */
|
|
37
|
+
combine,
|
|
38
|
+
/** @readonly */
|
|
39
|
+
pipex,
|
|
12
40
|
}
|