@fncts/io 0.0.9 → 0.0.12
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/Channel/api.d.ts +27 -4
- package/Channel/internal/MergeDecision.d.ts +14 -0
- package/IO/runtime.d.ts +8 -1
- package/STM/api.d.ts +7 -0
- package/Sink/api.d.ts +637 -8
- package/TReentrantLock/api.d.ts +97 -0
- package/TReentrantLock/definition.d.ts +65 -0
- package/TReentrantLock.d.ts +2 -0
- package/_cjs/Cached/api.cjs +1 -1
- package/_cjs/Cached/api.cjs.map +1 -1
- package/_cjs/Channel/api/mapOutIOC.cjs +1 -1
- package/_cjs/Channel/api/mapOutIOC.cjs.map +1 -1
- package/_cjs/Channel/api/mergeAllWith.cjs +2 -2
- package/_cjs/Channel/api/mergeAllWith.cjs.map +1 -1
- package/_cjs/Channel/api/mergeWith.cjs +1 -1
- package/_cjs/Channel/api/mergeWith.cjs.map +1 -1
- package/_cjs/Channel/api.cjs +87 -32
- package/_cjs/Channel/api.cjs.map +1 -1
- package/_cjs/Channel/internal/MergeDecision.cjs +11 -2
- package/_cjs/Channel/internal/MergeDecision.cjs.map +1 -1
- package/_cjs/IO/api/foreachC.cjs +2 -2
- package/_cjs/IO/api/foreachC.cjs.map +1 -1
- package/_cjs/IO/runtime.cjs +18 -7
- package/_cjs/IO/runtime.cjs.map +1 -1
- package/_cjs/STM/api.cjs +15 -6
- package/_cjs/STM/api.cjs.map +1 -1
- package/_cjs/Sink/api.cjs +1475 -42
- package/_cjs/Sink/api.cjs.map +1 -1
- package/_cjs/Stream/api.cjs +29 -29
- package/_cjs/Stream/api.cjs.map +1 -1
- package/_cjs/TReentrantLock/api.cjs +297 -0
- package/_cjs/TReentrantLock/api.cjs.map +1 -0
- package/_cjs/TReentrantLock/definition.cjs +125 -0
- package/_cjs/TReentrantLock/definition.cjs.map +1 -0
- package/_cjs/TReentrantLock.cjs +32 -0
- package/_cjs/TReentrantLock.cjs.map +1 -0
- package/_cjs/collection/immutable/Conc/dropUntilIO.cjs +38 -0
- package/_cjs/collection/immutable/Conc/dropUntilIO.cjs.map +1 -0
- package/_cjs/collection/immutable/Conc/dropWhileIO.cjs +38 -0
- package/_cjs/collection/immutable/Conc/dropWhileIO.cjs.map +1 -0
- package/_cjs/collection/immutable/Conc/filterIO.cjs +35 -0
- package/_cjs/collection/immutable/Conc/filterIO.cjs.map +1 -0
- package/_cjs/collection/immutable/Conc.cjs +13 -0
- package/_cjs/collection/immutable/Conc.cjs.map +1 -1
- package/_cjs/demo.cjs +15 -0
- package/_cjs/demo.cjs.map +1 -0
- package/_mjs/Cached/api.mjs +1 -1
- package/_mjs/Cached/api.mjs.map +1 -1
- package/_mjs/Channel/api/mapOutIOC.mjs +1 -1
- package/_mjs/Channel/api/mapOutIOC.mjs.map +1 -1
- package/_mjs/Channel/api/mergeAllWith.mjs +2 -2
- package/_mjs/Channel/api/mergeAllWith.mjs.map +1 -1
- package/_mjs/Channel/api/mergeWith.mjs +1 -1
- package/_mjs/Channel/api/mergeWith.mjs.map +1 -1
- package/_mjs/Channel/api.mjs +75 -30
- package/_mjs/Channel/api.mjs.map +1 -1
- package/_mjs/Channel/internal/MergeDecision.mjs +7 -0
- package/_mjs/Channel/internal/MergeDecision.mjs.map +1 -1
- package/_mjs/IO/api/foreachC.mjs +2 -2
- package/_mjs/IO/api/foreachC.mjs.map +1 -1
- package/_mjs/IO/runtime.mjs +15 -5
- package/_mjs/IO/runtime.mjs.map +1 -1
- package/_mjs/STM/api.mjs +13 -6
- package/_mjs/STM/api.mjs.map +1 -1
- package/_mjs/Sink/api.mjs +1287 -37
- package/_mjs/Sink/api.mjs.map +1 -1
- package/_mjs/Stream/api.mjs +29 -29
- package/_mjs/Stream/api.mjs.map +1 -1
- package/_mjs/TReentrantLock/api.mjs +243 -0
- package/_mjs/TReentrantLock/api.mjs.map +1 -0
- package/_mjs/TReentrantLock/definition.mjs +102 -0
- package/_mjs/TReentrantLock/definition.mjs.map +1 -0
- package/_mjs/TReentrantLock.mjs +4 -0
- package/_mjs/TReentrantLock.mjs.map +1 -0
- package/_mjs/collection/immutable/Conc/dropUntilIO.mjs +26 -0
- package/_mjs/collection/immutable/Conc/dropUntilIO.mjs.map +1 -0
- package/_mjs/collection/immutable/Conc/dropWhileIO.mjs +26 -0
- package/_mjs/collection/immutable/Conc/dropWhileIO.mjs.map +1 -0
- package/_mjs/collection/immutable/Conc/filterIO.mjs +22 -0
- package/_mjs/collection/immutable/Conc/filterIO.mjs.map +1 -0
- package/_mjs/collection/immutable/Conc.mjs +1 -0
- package/_mjs/collection/immutable/Conc.mjs.map +1 -1
- package/_mjs/demo.mjs +7 -0
- package/_mjs/demo.mjs.map +1 -0
- package/_src/Channel/api.ts +98 -11
- package/_src/Channel/internal/MergeDecision.ts +15 -0
- package/_src/IO/api.ts +1 -1
- package/_src/IO/runtime.ts +18 -11
- package/_src/STM/api.ts +9 -0
- package/_src/Sink/api.ts +1725 -36
- package/_src/TFuture/definition.ts +1 -1
- package/_src/TReentrantLock/api.ts +193 -0
- package/_src/TReentrantLock/definition.ts +86 -0
- package/_src/TReentrantLock.ts +4 -0
- package/_src/collection/immutable/Conc/dropUntilIO.ts +24 -0
- package/_src/collection/immutable/Conc/dropWhileIO.ts +26 -0
- package/_src/collection/immutable/Conc/filterIO.ts +16 -0
- package/_src/collection/immutable/Conc.ts +1 -0
- package/_src/demo.ts +6 -0
- package/collection/immutable/Conc/dropUntilIO.d.ts +7 -0
- package/collection/immutable/Conc/dropWhileIO.d.ts +7 -0
- package/collection/immutable/Conc/filterIO.d.ts +7 -0
- package/collection/immutable/Conc.d.ts +1 -0
- package/demo.d.ts +1 -0
- package/package.json +3 -3
package/_mjs/Sink/api.mjs
CHANGED
|
@@ -1,76 +1,1326 @@
|
|
|
1
|
-
|
|
2
|
-
import * as
|
|
3
|
-
import * as
|
|
4
|
-
import * as
|
|
5
|
-
import * as
|
|
6
|
-
import * as
|
|
7
|
-
|
|
1
|
+
const fileName_1 = "(@fncts/io) src/Sink/api.ts";
|
|
2
|
+
import * as tsplus_module_1 from "@fncts/base/collection/immutable/Conc/api/empty";
|
|
3
|
+
import * as tsplus_module_2 from "@fncts/base/collection/immutable/Conc/api";
|
|
4
|
+
import * as tsplus_module_3 from "@fncts/io/Sink/definition";
|
|
5
|
+
import * as tsplus_module_4 from "@fncts/io/Channel/api";
|
|
6
|
+
import * as tsplus_module_5 from "@fncts/io/Channel/core-api";
|
|
7
|
+
import * as tsplus_module_6 from "@fncts/io/Ref/api/set";
|
|
8
|
+
import * as tsplus_module_7 from "@fncts/io/Ref/api/get";
|
|
9
|
+
import * as tsplus_module_8 from "@fncts/io/Ref/constructors";
|
|
10
|
+
import * as tsplus_module_9 from "@fncts/io/IO/api";
|
|
11
|
+
import * as tsplus_module_10 from "@fncts/io/collection/immutable/Conc/mapIO";
|
|
12
|
+
import * as tsplus_module_11 from "@fncts/io/collection/immutable/Conc/dropUntilIO";
|
|
13
|
+
import * as tsplus_module_12 from "@fncts/io/collection/immutable/Conc/dropWhileIO";
|
|
14
|
+
import * as tsplus_module_13 from "@fncts/io/IO/api/environment";
|
|
15
|
+
import * as tsplus_module_14 from "@fncts/base/data/function/api";
|
|
16
|
+
import * as tsplus_module_15 from "@fncts/io/collection/immutable/Conc/filterIO";
|
|
17
|
+
import * as tsplus_module_16 from "@fncts/base/data/Maybe/constructors";
|
|
18
|
+
import * as tsplus_module_17 from "@fncts/base/data/Either/destructors";
|
|
19
|
+
import * as tsplus_module_18 from "@fncts/io/Queue/api/operations";
|
|
20
|
+
import * as tsplus_module_19 from "@fncts/io/IO/api/acquireRelease";
|
|
21
|
+
import * as tsplus_module_20 from "@fncts/base/data/Cause/api";
|
|
22
|
+
import * as tsplus_module_21 from "@fncts/base/data/Maybe/definition";
|
|
23
|
+
import * as tsplus_module_22 from "@fncts/base/data/Maybe/destructors";
|
|
24
|
+
import * as tsplus_module_23 from "@fncts/base/collection/immutable/Conc";
|
|
25
|
+
import * as tsplus_module_24 from "@fncts/base/collection/immutable/Conc/constructors";
|
|
26
|
+
import * as tsplus_module_25 from "@fncts/base/data/Either/api";
|
|
27
|
+
import * as tsplus_module_26 from "@fncts/base/data/Either/constructors";
|
|
28
|
+
import * as tsplus_module_27 from "@fncts/io/Channel/internal/MergeDecision";
|
|
29
|
+
import * as tsplus_module_28 from "@fncts/io/Channel/api/mergeWith";
|
|
30
|
+
import * as tsplus_module_29 from "@fncts/io/Hub/api";
|
|
31
|
+
import * as tsplus_module_30 from "@fncts/base/collection/Iterable/api";
|
|
32
|
+
import * as tsplus_module_31 from "@fncts/io/Clock/api";
|
|
33
|
+
import * as tsplus_module_32 from "@fncts/base/data/Duration/api";
|
|
34
|
+
import * as tsplus_module_33 from "@fncts/base/data/Exit/api";
|
|
35
|
+
export const collectAllWhileWith = collectAllWhileWith_1;
|
|
36
|
+
export const contramap = contramap_1;
|
|
37
|
+
export const contramapChunks = contramapChunks_1;
|
|
38
|
+
export const contramapChunksIO = contramapChunksIO_1;
|
|
39
|
+
export const contramapIO = contramapIO_1;
|
|
40
|
+
export const defer = defer_1;
|
|
41
|
+
export const failCause = failCause_1;
|
|
42
|
+
export const failCauseNow = failCauseNow_1;
|
|
43
|
+
export const failNow = failNow_1;
|
|
44
|
+
export const flatMap = flatMap_1;
|
|
45
|
+
export const fromQueue = fromQueue_1;
|
|
46
|
+
export const fromQueueWithShutdown = fromQueueWithShutdown_1;
|
|
47
|
+
export const fromIO = fromIO_1;
|
|
48
|
+
export const ignoreLeftover = ignoreLeftover_1;
|
|
49
|
+
export const makeForeachChunk = makeForeachChunk_1;
|
|
50
|
+
export const makeForeachWhile = makeForeachWhile_1;
|
|
51
|
+
export const makeFold = makeFold_1;
|
|
52
|
+
export const makeFoldUntil = makeFoldUntil_1;
|
|
53
|
+
export const makeFoldChunks = makeFoldChunks_1;
|
|
54
|
+
export const makeFoldChunksIO = makeFoldChunksIO_1;
|
|
55
|
+
export const makeFoldLeft = makeFoldLeft_1;
|
|
56
|
+
export const makeFoldIO = makeFoldIO_1;
|
|
57
|
+
export const makeFoldWeightedDecompose = makeFoldWeightedDecompose_1;
|
|
58
|
+
export const makeFoldWeightedDecomposeIO = makeFoldWeightedDecomposeIO_1;
|
|
59
|
+
export const map_ = map_1;
|
|
60
|
+
export const mapIO_ = mapIO_1;
|
|
61
|
+
export const matchSink_ = matchSink_1;
|
|
62
|
+
export const raceBoth = raceBoth_1;
|
|
63
|
+
export const raceWith = raceWith_1;
|
|
64
|
+
export const serviceWith = serviceWith_1;
|
|
65
|
+
export const summarized = summarized_1;
|
|
66
|
+
export const unwrap = unwrap_1;
|
|
67
|
+
export const unwrapScoped = unwrapScoped_1;
|
|
68
|
+
export const zipWith = zipWith_1;
|
|
69
|
+
export const zipWithC = zipWithC_1;
|
|
70
|
+
import { AtomicReference } from "@fncts/base/internal/AtomicReference";
|
|
71
|
+
/**
|
|
72
|
+
* Like {@link zip}, but keeps only the result from this sink
|
|
73
|
+
*
|
|
74
|
+
* @tsplus fluent fncts.io.Sink apFirst
|
|
75
|
+
*/
|
|
8
76
|
|
|
9
|
-
function
|
|
10
|
-
return
|
|
77
|
+
export function apFirst(self, that) {
|
|
78
|
+
return zipWith_1(() => self, that, (z, _) => z, fileName_1 + ":14:22");
|
|
11
79
|
}
|
|
12
80
|
/**
|
|
13
|
-
*
|
|
81
|
+
* Like {@link zipC}, but keeps only the result from this sink
|
|
14
82
|
*
|
|
15
|
-
* @tsplus
|
|
83
|
+
* @tsplus fluent fncts.io.Sink apFirstC
|
|
84
|
+
*/
|
|
85
|
+
|
|
86
|
+
export function apFirstC(self, that) {
|
|
87
|
+
return zipWithC_1(() => self, that, (z, _) => z, fileName_1 + ":26:23");
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Like {@link zip}, but keeps only the result from the `that` sink
|
|
91
|
+
*
|
|
92
|
+
* @tsplus fluent fncts.io.Sink apSecond
|
|
93
|
+
*/
|
|
94
|
+
|
|
95
|
+
export function apSecond(self, that, __tsplusTrace) {
|
|
96
|
+
return zipWith_1(() => self, that, (_, z1) => z1, __tsplusTrace);
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Like {@link zipC}, but keeps only the result from the `that` sink
|
|
100
|
+
*
|
|
101
|
+
* @tsplus fluent fncts.io.Sink apSecondC
|
|
102
|
+
*/
|
|
103
|
+
|
|
104
|
+
export function apSecondC(self, that, __tsplusTrace) {
|
|
105
|
+
return zipWithC_1(() => self, that, (_, z1) => z1, __tsplusTrace);
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Replaces this sink's result with the provided value.
|
|
109
|
+
*
|
|
110
|
+
* @tsplus fluent fncts.io.Sink as
|
|
111
|
+
*/
|
|
112
|
+
|
|
113
|
+
export function as(self, z, __tsplusTrace) {
|
|
114
|
+
return map_1(self, () => z(), __tsplusTrace);
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Repeatedly runs the sink and accumulates its results into a chunk
|
|
118
|
+
*
|
|
119
|
+
* @tsplus fluent fncts.io.Sink collectAll
|
|
120
|
+
*/
|
|
121
|
+
|
|
122
|
+
export function collectAll(self, __tsplusTrace) {
|
|
123
|
+
return collectAllWhileWith_1(self, () => tsplus_module_1.empty(), () => true, (s, z) => tsplus_module_2.append_(s, z), __tsplusTrace);
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Repeatedly runs the sink for as long as its results satisfy the predicate
|
|
127
|
+
* `p`. The sink's results will be accumulated using the stepping function
|
|
128
|
+
* `f`.
|
|
129
|
+
*
|
|
130
|
+
* @tsplus fluent fncts.io.Sink collectAllWhileWith
|
|
131
|
+
*/
|
|
132
|
+
|
|
133
|
+
function collectAllWhileWith_1(self, z, p, f, __tsplusTrace) {
|
|
134
|
+
return new tsplus_module_3.Sink(tsplus_module_5.flatMap_(tsplus_module_4.fromIO(() => tsplus_module_9.zip_(tsplus_module_8.make(() => tsplus_module_1.empty()), tsplus_module_8.make(() => false))), ([leftoversRef, upstreamDoneRef]) => {
|
|
135
|
+
const upstreamMarker = tsplus_module_4.readWith(inp => tsplus_module_5.apSecond_(tsplus_module_4.writeNow(inp), upstreamMarker), tsplus_module_4.failNow, x => tsplus_module_4.as_(tsplus_module_4.fromIO(() => tsplus_module_6.set_(upstreamDoneRef, true)), () => x));
|
|
136
|
+
|
|
137
|
+
function loop(currentResult) {
|
|
138
|
+
return tsplus_module_4.matchChannel_(tsplus_module_4.collectElements(self.channel), tsplus_module_4.failNow, ([leftovers, doneValue]) => {
|
|
139
|
+
if (p(doneValue)) {
|
|
140
|
+
return tsplus_module_5.apSecond_(tsplus_module_4.fromIO(() => tsplus_module_6.set_(leftoversRef, tsplus_module_2.flatten(leftovers))), tsplus_module_5.flatMap_(tsplus_module_4.fromIO(() => tsplus_module_7.get(upstreamDoneRef)), upstreamDone => {
|
|
141
|
+
const accumulatedResult = f(currentResult, doneValue);
|
|
142
|
+
if (upstreamDone) return tsplus_module_4.as_(tsplus_module_4.writeNow(tsplus_module_2.flatten(leftovers)), () => accumulatedResult);else return loop(accumulatedResult);
|
|
143
|
+
}));
|
|
144
|
+
} else {
|
|
145
|
+
return tsplus_module_4.as_(tsplus_module_4.writeNow(tsplus_module_2.flatten(leftovers)), () => currentResult);
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
return tsplus_module_4.pipeTo_(tsplus_module_4.pipeTo_(upstreamMarker, tsplus_module_4.bufferChunk(leftoversRef)), loop(z()));
|
|
151
|
+
}));
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Collects the leftovers from the stream when the sink succeeds and returns
|
|
155
|
+
* them as part of the sink's result
|
|
156
|
+
*
|
|
157
|
+
* @tsplus getter fncts.io.Sink collectLeftover
|
|
158
|
+
*/
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
export function collectLeftover(self, __tsplusTrace) {
|
|
162
|
+
return new tsplus_module_3.Sink(tsplus_module_5.map_(tsplus_module_4.collectElements(self.channel), ([chunks, z]) => [z, tsplus_module_2.flatten(chunks)]));
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Transforms this sink's input elements.
|
|
166
|
+
*
|
|
167
|
+
* @tsplus fluent fncts.io.Sink contramap
|
|
168
|
+
*/
|
|
169
|
+
|
|
170
|
+
function contramap_1(self, f, __tsplusTrace) {
|
|
171
|
+
return contramapChunks_1(self, chunk => tsplus_module_2.map_(chunk, f), __tsplusTrace);
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Transforms this sink's input chunks. `f` must preserve chunking-invariance
|
|
175
|
+
*
|
|
176
|
+
* @tsplus fluent fncts.io.Sink contramapChunks
|
|
177
|
+
*/
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
function contramapChunks_1(self, f, __tsplusTrace) {
|
|
181
|
+
const loop = tsplus_module_4.readWith(chunk => tsplus_module_5.apSecond_(tsplus_module_4.writeNow(f(chunk)), loop), tsplus_module_4.failNow, tsplus_module_5.succeedNow);
|
|
182
|
+
return new tsplus_module_3.Sink(tsplus_module_4.pipeTo_(loop, self.channel));
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Effectfully transforms this sink's input chunks. `f` must preserve
|
|
186
|
+
* chunking-invariance
|
|
187
|
+
*
|
|
188
|
+
* @tsplus fluent fncts.io.Sink contramapChunksIO
|
|
189
|
+
*/
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
function contramapChunksIO_1(self, f, __tsplusTrace) {
|
|
193
|
+
const loop = tsplus_module_4.readWith(chunk => tsplus_module_5.apSecond_(tsplus_module_5.flatMap_(tsplus_module_4.fromIO(() => f(chunk)), tsplus_module_4.writeNow), loop), tsplus_module_4.failNow, tsplus_module_5.succeedNow);
|
|
194
|
+
return new tsplus_module_3.Sink(tsplus_module_4.pipeToOrFail_(loop, self.channel));
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Effectfully transforms this sink's input elements.
|
|
198
|
+
*
|
|
199
|
+
* @tsplus fluent fncts.io.Sink contramapIO
|
|
200
|
+
*/
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
function contramapIO_1(self, f, __tsplusTrace) {
|
|
204
|
+
return contramapChunksIO_1(self, chunk => tsplus_module_10.mapIO_(chunk, f), __tsplusTrace);
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Transforms both inputs and result of this sink using the provided
|
|
208
|
+
* functions.
|
|
209
|
+
*
|
|
210
|
+
* @tsplus fluent fncts.io.Sink dimap
|
|
211
|
+
*/
|
|
212
|
+
|
|
213
|
+
|
|
214
|
+
export function dimap(self, f, g, __tsplusTrace) {
|
|
215
|
+
return map_1(contramap_1(self, f, __tsplusTrace), g, __tsplusTrace);
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Transforms both input chunks and result of this sink using the provided
|
|
219
|
+
* functions.
|
|
220
|
+
*
|
|
221
|
+
* @tsplus fluent fncts.io.Sink dimapChunks
|
|
222
|
+
*/
|
|
223
|
+
|
|
224
|
+
export function dimapChunks(self, f, g, __tsplusTrace) {
|
|
225
|
+
return map_1(contramapChunks_1(self, f, __tsplusTrace), g, __tsplusTrace);
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* Effectfully transforms both input chunks and result of this sink using the
|
|
229
|
+
* provided functions. `f` and `g` must preserve chunking-invariance
|
|
230
|
+
*
|
|
231
|
+
* @tsplus fluent fncts.io.Sink dimapChunksIO
|
|
232
|
+
*/
|
|
233
|
+
|
|
234
|
+
export function dimapChunksIO(self, f, g, __tsplusTrace) {
|
|
235
|
+
return mapIO_1(contramapChunksIO_1(self, f, __tsplusTrace), g, __tsplusTrace);
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Effectfully transforms both inputs and result of this sink using the
|
|
239
|
+
* provided functions.
|
|
240
|
+
*
|
|
241
|
+
* @tsplus fluent fncts.io.Sink dimapIO
|
|
16
242
|
*/
|
|
17
243
|
|
|
244
|
+
export function dimapIO(self, f, g, __tsplusTrace) {
|
|
245
|
+
return mapIO_1(contramapIO_1(self, f, __tsplusTrace), g, __tsplusTrace);
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* Returns a lazily constructed sink that may require effects for its
|
|
249
|
+
* creation.
|
|
250
|
+
*
|
|
251
|
+
* @tsplus static fncts.io.SinkOps defer
|
|
252
|
+
*/
|
|
18
253
|
|
|
19
|
-
|
|
20
|
-
return new
|
|
254
|
+
function defer_1(sink, __tsplusTrace) {
|
|
255
|
+
return new tsplus_module_3.Sink(tsplus_module_4.defer(() => sink().channel));
|
|
21
256
|
}
|
|
22
|
-
|
|
257
|
+
|
|
258
|
+
const drainLoop = /*#__PURE__*/tsplus_module_4.readWithCause(() => drainLoop, tsplus_module_5.failCauseNow, () => tsplus_module_4.unit);
|
|
23
259
|
/**
|
|
24
260
|
* A sink that ignores all of its inputs.
|
|
25
261
|
*
|
|
26
262
|
* @tsplus static fncts.io.SinkOps drain
|
|
27
263
|
*/
|
|
28
264
|
|
|
29
|
-
export const drain = /*#__PURE__*/new
|
|
265
|
+
export const drain = /*#__PURE__*/new tsplus_module_3.Sink(drainLoop);
|
|
266
|
+
/**
|
|
267
|
+
* Drops incoming elements until the predicate `p` is satisfied.
|
|
268
|
+
*
|
|
269
|
+
* @tsplus static fncts.io.SinkOps dropUntil
|
|
270
|
+
*/
|
|
271
|
+
|
|
272
|
+
export function makeDropUntil(p, __tsplusTrace) {
|
|
273
|
+
const loop = tsplus_module_4.readWith(inp => {
|
|
274
|
+
const leftover = tsplus_module_2.dropUntil(inp, p);
|
|
275
|
+
const more = tsplus_module_2.isEmpty(leftover);
|
|
276
|
+
|
|
277
|
+
if (more) {
|
|
278
|
+
return loop;
|
|
279
|
+
} else {
|
|
280
|
+
return tsplus_module_5.apSecond_(tsplus_module_4.writeNow(leftover), tsplus_module_4.id());
|
|
281
|
+
}
|
|
282
|
+
}, tsplus_module_4.failNow, () => tsplus_module_4.unit);
|
|
283
|
+
return new tsplus_module_3.Sink(loop);
|
|
284
|
+
}
|
|
285
|
+
/**
|
|
286
|
+
* Drops incoming elements until the effectful predicate `p` is satisfied.
|
|
287
|
+
*
|
|
288
|
+
* @tsplus static fncts.io.SinkOps dropUntilIO
|
|
289
|
+
*/
|
|
290
|
+
|
|
291
|
+
export function makeDropUntilIO(p, __tsplusTrace) {
|
|
292
|
+
const loop = tsplus_module_4.readWith(inp => tsplus_module_4.unwrap(() => tsplus_module_9.map_(tsplus_module_11.dropUntilIO(inp, p, __tsplusTrace), leftover => tsplus_module_2.isEmpty(leftover) ? loop : tsplus_module_5.apSecond_(tsplus_module_4.writeNow(leftover), tsplus_module_4.id()), __tsplusTrace)), tsplus_module_4.failNow, () => tsplus_module_4.unit);
|
|
293
|
+
return new tsplus_module_3.Sink(loop);
|
|
294
|
+
}
|
|
30
295
|
/**
|
|
296
|
+
* Drops incoming elements as long as the predicate `p` is satisfied.
|
|
297
|
+
*
|
|
31
298
|
* @tsplus static fncts.io.SinkOps dropWhile
|
|
32
299
|
*/
|
|
33
300
|
|
|
34
|
-
export function
|
|
35
|
-
const loop =
|
|
36
|
-
const leftover =
|
|
37
|
-
const more =
|
|
301
|
+
export function makeDropWhile(predicate, __tsplusTrace) {
|
|
302
|
+
const loop = tsplus_module_4.readWith(inp => {
|
|
303
|
+
const leftover = tsplus_module_2.dropWhile_(inp, predicate);
|
|
304
|
+
const more = tsplus_module_2.isEmpty(leftover);
|
|
38
305
|
|
|
39
306
|
if (more) {
|
|
40
307
|
return loop;
|
|
41
308
|
} else {
|
|
42
|
-
return
|
|
309
|
+
return tsplus_module_5.apSecond_(tsplus_module_4.writeNow(leftover), tsplus_module_4.id());
|
|
43
310
|
}
|
|
44
|
-
},
|
|
45
|
-
return new
|
|
311
|
+
}, tsplus_module_4.failNow, () => tsplus_module_4.unit);
|
|
312
|
+
return new tsplus_module_3.Sink(loop);
|
|
46
313
|
}
|
|
47
314
|
/**
|
|
48
|
-
*
|
|
315
|
+
* Drops incoming elements as long as the effectful predicate `p` is
|
|
316
|
+
* satisfied.
|
|
49
317
|
*
|
|
50
|
-
* @tsplus static fncts.io.SinkOps
|
|
318
|
+
* @tsplus static fncts.io.SinkOps dropWhileIO
|
|
51
319
|
*/
|
|
52
320
|
|
|
53
|
-
export function
|
|
54
|
-
|
|
321
|
+
export function dropWhileIO(p, __tsplusTrace) {
|
|
322
|
+
const loop = tsplus_module_4.readWith(inp => tsplus_module_4.unwrap(() => tsplus_module_9.map_(tsplus_module_12.dropWhileIO(inp, p, __tsplusTrace), leftover => tsplus_module_2.isEmpty(leftover) ? loop : tsplus_module_5.apSecond_(tsplus_module_4.writeNow(leftover), tsplus_module_4.id()), __tsplusTrace)), tsplus_module_4.failNow, () => tsplus_module_4.unit);
|
|
323
|
+
return new tsplus_module_3.Sink(loop);
|
|
55
324
|
}
|
|
325
|
+
/**
|
|
326
|
+
* Accesses the whole environment of the sink.
|
|
327
|
+
*
|
|
328
|
+
* @tsplus static fncts.io.SinkOps environment
|
|
329
|
+
*/
|
|
56
330
|
|
|
57
|
-
function
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
331
|
+
export function environment(__tsplusTrace) {
|
|
332
|
+
return fromIO_1(() => tsplus_module_13.environment(__tsplusTrace), __tsplusTrace);
|
|
333
|
+
}
|
|
334
|
+
/**
|
|
335
|
+
* Accesses the environment of the sink.
|
|
336
|
+
*
|
|
337
|
+
* @tsplus static fncts.io.SinkOps environmentWith
|
|
338
|
+
*/
|
|
61
339
|
|
|
62
|
-
|
|
340
|
+
export function environmentWith(f, __tsplusTrace) {
|
|
341
|
+
return fromIO_1(() => tsplus_module_13.environmentWith(f, __tsplusTrace), __tsplusTrace);
|
|
63
342
|
}
|
|
64
343
|
/**
|
|
65
|
-
*
|
|
66
|
-
* until `f` evaluates to `false`.
|
|
344
|
+
* Accesses the environment of the sink in the context of an effect.
|
|
67
345
|
*
|
|
68
|
-
* @tsplus static fncts.io.SinkOps
|
|
346
|
+
* @tsplus static fncts.io.SinkOps environmentWithIO
|
|
347
|
+
*/
|
|
348
|
+
|
|
349
|
+
export function environmentWithIO(f, __tsplusTrace) {
|
|
350
|
+
return fromIO_1(() => tsplus_module_13.environmentWithIO(f, __tsplusTrace), __tsplusTrace);
|
|
351
|
+
}
|
|
352
|
+
/**
|
|
353
|
+
* Accesses the environment of the sink in the context of a sink.
|
|
354
|
+
*
|
|
355
|
+
* @tsplus static fncts.io.SinkOps environmentWithSink
|
|
356
|
+
*/
|
|
357
|
+
|
|
358
|
+
export function environmentWithSink(f, __tsplusTrace) {
|
|
359
|
+
return new tsplus_module_3.Sink(tsplus_module_4.unwrap(() => tsplus_module_13.environmentWith(tsplus_module_14.compose_(f, s => s.channel), __tsplusTrace)));
|
|
360
|
+
}
|
|
361
|
+
/**
|
|
362
|
+
* A sink that always fails with the specified error.
|
|
363
|
+
*
|
|
364
|
+
* @tsplus static fncts.io.SinkOps fail
|
|
365
|
+
*/
|
|
366
|
+
|
|
367
|
+
export function fail(e, __tsplusTrace) {
|
|
368
|
+
return new tsplus_module_3.Sink(tsplus_module_4.fail(e));
|
|
369
|
+
}
|
|
370
|
+
/**
|
|
371
|
+
* Creates a sink halting with a specified cause.
|
|
372
|
+
*
|
|
373
|
+
* @tsplus static fncts.io.SinkOps failCause
|
|
374
|
+
*/
|
|
375
|
+
|
|
376
|
+
function failCause_1(cause, __tsplusTrace) {
|
|
377
|
+
return new tsplus_module_3.Sink(tsplus_module_5.failCause(cause));
|
|
378
|
+
}
|
|
379
|
+
/**
|
|
380
|
+
* Creates a sink halting with a specified cause.
|
|
381
|
+
*
|
|
382
|
+
* @tsplus static fncts.io.SinkOps failCauseNow
|
|
383
|
+
*/
|
|
384
|
+
|
|
385
|
+
|
|
386
|
+
function failCauseNow_1(cause, __tsplusTrace) {
|
|
387
|
+
return new tsplus_module_3.Sink(tsplus_module_5.failCauseNow(cause));
|
|
388
|
+
}
|
|
389
|
+
/**
|
|
390
|
+
* A sink that always fails with the specified error.
|
|
391
|
+
*
|
|
392
|
+
* @tsplus static fncts.io.SinkOps failNow
|
|
393
|
+
*/
|
|
394
|
+
|
|
395
|
+
|
|
396
|
+
function failNow_1(e, __tsplusTrace) {
|
|
397
|
+
return new tsplus_module_3.Sink(tsplus_module_4.failNow(e));
|
|
398
|
+
}
|
|
399
|
+
/**
|
|
400
|
+
* Filters the sink's input with the given predicate
|
|
401
|
+
*
|
|
402
|
+
* @tsplus static fncts.io.SinkOps filterInput
|
|
403
|
+
*/
|
|
404
|
+
|
|
405
|
+
|
|
406
|
+
export function filterInput(self, p, __tsplusTrace) {
|
|
407
|
+
return contramapChunks_1(self, chunk => tsplus_module_2.filter_(chunk, p), __tsplusTrace);
|
|
408
|
+
}
|
|
409
|
+
/**
|
|
410
|
+
* Filters the sink's input with the given IO predicate
|
|
411
|
+
*
|
|
412
|
+
* @tsplus static fncts.io.SinkOps filterInputIO
|
|
413
|
+
*/
|
|
414
|
+
|
|
415
|
+
export function filterInputIO(self, p, __tsplusTrace) {
|
|
416
|
+
return contramapChunksIO_1(self, chunk => tsplus_module_15.filterIO(chunk, p), __tsplusTrace);
|
|
417
|
+
}
|
|
418
|
+
/**
|
|
419
|
+
* Creates a sink that produces values until one verifies the predicate `f`.
|
|
420
|
+
*
|
|
421
|
+
* @tsplus fluent fncts.io.Sink findIO
|
|
422
|
+
*/
|
|
423
|
+
|
|
424
|
+
export function findIO(self, f, __tsplusTrace) {
|
|
425
|
+
return new tsplus_module_3.Sink(tsplus_module_5.flatMap_(tsplus_module_4.fromIO(() => tsplus_module_9.zip_(tsplus_module_8.make(() => tsplus_module_1.empty()), tsplus_module_8.make(() => false))), ([leftoversRef, upstreamDoneRef]) => {
|
|
426
|
+
const upstreamMarker = tsplus_module_4.readWith(inp => tsplus_module_5.apSecond_(tsplus_module_4.writeNow(inp), upstreamMarker), tsplus_module_4.failNow, x => tsplus_module_4.as_(tsplus_module_4.fromIO(() => tsplus_module_6.set_(upstreamDoneRef, true)), () => x));
|
|
427
|
+
const loop = tsplus_module_4.matchChannel_(tsplus_module_4.collectElements(self.channel), tsplus_module_4.failNow, ([leftovers, doneValue]) => tsplus_module_5.flatMap_(tsplus_module_4.fromIO(() => f(doneValue)), satisfied => tsplus_module_5.apSecond_(tsplus_module_4.fromIO(() => tsplus_module_6.set_(leftoversRef, tsplus_module_2.flatten(leftovers))), tsplus_module_5.flatMap_(tsplus_module_4.fromIO(() => tsplus_module_7.get(upstreamDoneRef)), upstreamDone => {
|
|
428
|
+
if (satisfied) return tsplus_module_4.as_(tsplus_module_4.writeNow(tsplus_module_2.flatten(leftovers)), () => tsplus_module_16.just(doneValue));else if (upstreamDone) return tsplus_module_4.as_(tsplus_module_4.writeNow(tsplus_module_2.flatten(leftovers)), () => tsplus_module_16.nothing());else return loop;
|
|
429
|
+
}))));
|
|
430
|
+
return tsplus_module_4.pipeTo_(tsplus_module_4.pipeTo_(upstreamMarker, tsplus_module_4.bufferChunk(leftoversRef)), loop);
|
|
431
|
+
}));
|
|
432
|
+
}
|
|
433
|
+
/**
|
|
434
|
+
* Runs this sink until it yields a result, then uses that result to create
|
|
435
|
+
* another sink from the provided function which will continue to run until it
|
|
436
|
+
* yields a result.
|
|
437
|
+
*
|
|
438
|
+
* This function essentially runs sinks in sequence.
|
|
439
|
+
*
|
|
440
|
+
* @tsplus fluent fncts.io.Sink flatMap
|
|
441
|
+
*/
|
|
442
|
+
|
|
443
|
+
function flatMap_1(self, f, __tsplusTrace) {
|
|
444
|
+
return matchSink_1(self, failNow_1, f, __tsplusTrace);
|
|
445
|
+
}
|
|
446
|
+
/**
|
|
447
|
+
* Creates a sink from a {@link Channel}
|
|
448
|
+
*
|
|
449
|
+
* @tsplus static fncts.io.SinkOps fromChannel
|
|
450
|
+
* @tsplus static fncts.io.SinkOps __call
|
|
451
|
+
*/
|
|
452
|
+
|
|
453
|
+
|
|
454
|
+
export function fromChannel(channel) {
|
|
455
|
+
return new tsplus_module_3.Sink(channel);
|
|
456
|
+
}
|
|
457
|
+
/**
|
|
458
|
+
* Creates a sink from a chunk processing function.
|
|
459
|
+
*
|
|
460
|
+
* @tsplus static fncts.io.SinkOps fromPush
|
|
461
|
+
*/
|
|
462
|
+
|
|
463
|
+
export function fromPush(push, __tsplusTrace) {
|
|
464
|
+
return new tsplus_module_3.Sink(tsplus_module_4.unwrapScoped(() => tsplus_module_9.map_(push, fromPushPull, __tsplusTrace)));
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
function fromPushPull(push) {
|
|
468
|
+
return tsplus_module_4.readWith(inp => tsplus_module_4.matchChannel_(tsplus_module_4.fromIO(() => push(tsplus_module_16.just(inp))), ([r, leftovers]) => tsplus_module_17.match_(r, e => tsplus_module_5.apSecond_(tsplus_module_4.writeNow(leftovers), tsplus_module_4.failNow(e)), z => tsplus_module_5.apSecond_(tsplus_module_4.writeNow(leftovers), tsplus_module_5.succeedNow(z))), () => fromPushPull(push)), tsplus_module_4.failNow, () => tsplus_module_4.matchChannel_(tsplus_module_4.fromIO(() => push(tsplus_module_16.nothing())), ([r, leftovers]) => tsplus_module_17.match_(r, e => tsplus_module_5.apSecond_(tsplus_module_4.writeNow(leftovers), tsplus_module_4.failNow(e)), z => tsplus_module_5.apSecond_(tsplus_module_4.writeNow(leftovers), tsplus_module_5.succeedNow(z))), () => tsplus_module_4.fromIO(() => tsplus_module_9.halt(() => new Error("empty sink"), fileName_1 + ":591:37"))));
|
|
469
|
+
}
|
|
470
|
+
/**
|
|
471
|
+
* Create a sink which enqueues each element into the specified queue.
|
|
472
|
+
*
|
|
473
|
+
* @tsplus static fncts.io.SinkOps fromQueue
|
|
474
|
+
*/
|
|
475
|
+
|
|
476
|
+
|
|
477
|
+
function fromQueue_1(queue, __tsplusTrace) {
|
|
478
|
+
return unwrap_1(() => tsplus_module_9.map_(tsplus_module_9.succeed(queue, __tsplusTrace), queue => makeForeachChunk_1(inp => tsplus_module_18.offerAll_(queue, inp), __tsplusTrace), __tsplusTrace));
|
|
479
|
+
}
|
|
480
|
+
/**
|
|
481
|
+
* Create a sink which enqueues each element into the specified queue. The
|
|
482
|
+
* queue will be shutdown once the stream is closed.
|
|
483
|
+
*
|
|
484
|
+
* @tsplus static fncts.io.SinkOps fromQueueWithShutdown
|
|
485
|
+
*/
|
|
486
|
+
|
|
487
|
+
|
|
488
|
+
function fromQueueWithShutdown_1(queue, __tsplusTrace) {
|
|
489
|
+
return unwrapScoped_1(() => tsplus_module_9.map_(tsplus_module_19.acquireRelease(() => tsplus_module_9.succeed(queue, __tsplusTrace), queue => tsplus_module_18.shutdown(queue)), queue => fromQueue_1(() => queue, __tsplusTrace), __tsplusTrace), __tsplusTrace);
|
|
490
|
+
}
|
|
491
|
+
/**
|
|
492
|
+
* Create a sink which publishes each element to the specified hub.
|
|
493
|
+
*
|
|
494
|
+
* @tsplus static fncts.io.SinkOps fromHub
|
|
495
|
+
*/
|
|
496
|
+
|
|
497
|
+
|
|
498
|
+
export function fromHub(hub, __tsplusTrace) {
|
|
499
|
+
return fromQueue_1(hub, __tsplusTrace);
|
|
500
|
+
}
|
|
501
|
+
/**
|
|
502
|
+
* Create a sink which publishes each element to the specified hub. The hub
|
|
503
|
+
* will be shutdown once the stream is closed.
|
|
504
|
+
*
|
|
505
|
+
* @tsplus static fncts.io.SinkOps fromHubWithShutdown
|
|
506
|
+
*/
|
|
507
|
+
|
|
508
|
+
export function fromHubWithShutdown(hub, __tsplusTrace) {
|
|
509
|
+
return fromQueueWithShutdown_1(hub, __tsplusTrace);
|
|
510
|
+
}
|
|
511
|
+
/**
|
|
512
|
+
* Creates a single-value sink produced from an effect
|
|
513
|
+
*
|
|
514
|
+
* @tsplus static fncts.io.SinkOps fromIO
|
|
515
|
+
*/
|
|
516
|
+
|
|
517
|
+
function fromIO_1(b, __tsplusTrace) {
|
|
518
|
+
return new tsplus_module_3.Sink(tsplus_module_4.fromIO(b));
|
|
519
|
+
}
|
|
520
|
+
/**
|
|
521
|
+
* Creates a sink halting with the specified unchecked value.
|
|
522
|
+
*
|
|
523
|
+
* @tsplus static fncts.io.SinkOps halt
|
|
524
|
+
*/
|
|
525
|
+
|
|
526
|
+
|
|
527
|
+
export function halt(defect, __tsplusTrace) {
|
|
528
|
+
return failCause_1(() => tsplus_module_20.halt(defect()), __tsplusTrace);
|
|
529
|
+
}
|
|
530
|
+
/**
|
|
531
|
+
* Creates a sink halting with the specified unchecked value.
|
|
532
|
+
*
|
|
533
|
+
* @tsplus static fncts.io.SinkOps haltNow
|
|
534
|
+
*/
|
|
535
|
+
|
|
536
|
+
export function haltNow(defect, __tsplusTrace) {
|
|
537
|
+
return failCauseNow_1(tsplus_module_20.halt(defect), __tsplusTrace);
|
|
538
|
+
}
|
|
539
|
+
/**
|
|
540
|
+
* Creates a sink containing the first value.
|
|
541
|
+
*
|
|
542
|
+
* @tsplus static fncts.io.SinkOps head
|
|
543
|
+
*/
|
|
544
|
+
|
|
545
|
+
export function head(__tsplusTrace) {
|
|
546
|
+
return makeFold_1(() => tsplus_module_16.nothing(), elem => tsplus_module_21.isNothing(elem), (s, inp) => tsplus_module_22.match_(s, () => tsplus_module_16.just(inp), () => s), __tsplusTrace);
|
|
547
|
+
}
|
|
548
|
+
/**
|
|
549
|
+
* Drains the remaining elements from the stream after the sink finishes
|
|
550
|
+
*
|
|
551
|
+
* @tsplus getter fncts.io.Sink ignoreLeftover
|
|
552
|
+
*/
|
|
553
|
+
|
|
554
|
+
function ignoreLeftover_1(self, __tsplusTrace) {
|
|
555
|
+
return new tsplus_module_3.Sink(tsplus_module_4.drain(self.channel));
|
|
556
|
+
}
|
|
557
|
+
/**
|
|
558
|
+
* Creates a sink containing the last value.
|
|
559
|
+
*
|
|
560
|
+
* @tsplus static fncts.io.SinkOps last
|
|
561
|
+
*/
|
|
562
|
+
|
|
563
|
+
|
|
564
|
+
export function last(__tsplusTrace) {
|
|
565
|
+
return makeFoldLeft_1(() => tsplus_module_16.nothing(), (_, inp) => tsplus_module_16.just(inp));
|
|
566
|
+
}
|
|
567
|
+
/**
|
|
568
|
+
* Creates a sink that does not consume any input but provides the given chunk
|
|
569
|
+
* as its leftovers
|
|
570
|
+
*
|
|
571
|
+
* @tsplus static fncts.io.SinkOps leftover
|
|
572
|
+
*/
|
|
573
|
+
|
|
574
|
+
export function leftover(c, __tsplusTrace) {
|
|
575
|
+
return new tsplus_module_3.Sink(tsplus_module_4.write(c));
|
|
576
|
+
}
|
|
577
|
+
/**
|
|
578
|
+
* Logs the specified message at the current log level.
|
|
579
|
+
*
|
|
580
|
+
* @tsplus static fncts.io.SinkOps log
|
|
581
|
+
*/
|
|
582
|
+
|
|
583
|
+
export function log(message, __tsplusTrace) {
|
|
584
|
+
return fromIO_1(() => tsplus_module_9.log(message, __tsplusTrace), __tsplusTrace);
|
|
585
|
+
}
|
|
586
|
+
/**
|
|
587
|
+
* A sink that collects all of its inputs into a chunk.
|
|
588
|
+
*
|
|
589
|
+
* @tsplus static fncts.io.SinkOps collectAll
|
|
590
|
+
*/
|
|
591
|
+
|
|
592
|
+
export function makeCollectAll() {
|
|
593
|
+
return new tsplus_module_3.Sink(collectLoop(tsplus_module_1.empty()));
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
function collectLoop(state) {
|
|
597
|
+
return tsplus_module_4.readWithCause(inp => collectLoop(tsplus_module_2.concat_(state, inp)), tsplus_module_5.failCauseNow, () => tsplus_module_5.endNow(state));
|
|
598
|
+
}
|
|
599
|
+
/**
|
|
600
|
+
* A sink that collects first `n` elements into a chunk. Note that the chunk
|
|
601
|
+
* is preallocated and must fit in memory.
|
|
602
|
+
*
|
|
603
|
+
* @tsplus static fncts.io.SinkOps collectAllN
|
|
604
|
+
*/
|
|
605
|
+
|
|
606
|
+
|
|
607
|
+
export function makeCollectAllN(n) {
|
|
608
|
+
return flatMap_1(fromIO_1(() => tsplus_module_9.succeed(() => new tsplus_module_23.ConcBuilder(), fileName_1 + ":755:32"), fileName_1 + ":755:21"), builder => map_1(makeFoldUntil_1(() => builder, n, (builder, inp) => builder.append(inp), fileName_1 + ":756:19"), builder => builder.result(), fileName_1 + ":756:95"), fileName_1 + ":755:64");
|
|
609
|
+
}
|
|
610
|
+
/**
|
|
611
|
+
* A sink that executes the provided effectful function for every element fed to it.
|
|
612
|
+
*
|
|
613
|
+
* @tsplus static fncts.io.SinkOps foreach
|
|
614
|
+
*/
|
|
615
|
+
|
|
616
|
+
export function makeForeach(f, __tsplusTrace) {
|
|
617
|
+
return makeForeachWhile_1(inp => tsplus_module_9.as_(f(inp), () => true), __tsplusTrace);
|
|
618
|
+
}
|
|
619
|
+
/**
|
|
620
|
+
* A sink that executes the provided effectful function for every chunk fed to
|
|
621
|
+
* it.
|
|
622
|
+
*
|
|
623
|
+
* @tsplus static fncts.io.SinkOps foreachChunk
|
|
624
|
+
*/
|
|
625
|
+
|
|
626
|
+
function makeForeachChunk_1(f, __tsplusTrace) {
|
|
627
|
+
const process = tsplus_module_4.readWithCause(inp => tsplus_module_5.apSecond_(tsplus_module_4.fromIO(() => f(inp)), process), tsplus_module_5.failCauseNow, () => tsplus_module_4.unit);
|
|
628
|
+
return new tsplus_module_3.Sink(process);
|
|
629
|
+
}
|
|
630
|
+
/**
|
|
631
|
+
* A sink that executes the provided effectful function for every element fed to it
|
|
632
|
+
* until `f` evaluates to `false`.
|
|
633
|
+
*
|
|
634
|
+
* @tsplus static fncts.io.SinkOps foreachWhile
|
|
635
|
+
*/
|
|
636
|
+
|
|
637
|
+
|
|
638
|
+
function makeForeachWhile_1(f, __tsplusTrace) {
|
|
639
|
+
const process = tsplus_module_4.readWithCause(inp => foreachWhileLoop(f, inp, 0, inp.length, process), tsplus_module_5.failCauseNow, () => tsplus_module_4.unit);
|
|
640
|
+
return new tsplus_module_3.Sink(process);
|
|
641
|
+
}
|
|
642
|
+
|
|
643
|
+
function foreachWhileLoop(f, chunk, idx, len, cont) {
|
|
644
|
+
if (idx === len) {
|
|
645
|
+
return cont;
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
return tsplus_module_4.catchAll_(tsplus_module_5.flatMap_(tsplus_module_4.fromIO(() => f(tsplus_module_2.unsafeGet_(chunk, idx))), b => b ? foreachWhileLoop(f, chunk, idx + 1, len, cont) : tsplus_module_4.writeNow(tsplus_module_2.drop_(chunk, idx))), e => tsplus_module_5.apSecond_(tsplus_module_4.writeNow(tsplus_module_2.drop_(chunk, idx)), tsplus_module_4.failNow(e)));
|
|
649
|
+
}
|
|
650
|
+
/**
|
|
651
|
+
* A sink that executes the provided effectful function for every chunk fed to
|
|
652
|
+
* it until `f` evaluates to `false`.
|
|
653
|
+
*
|
|
654
|
+
* @tsplus static fncts.io.SinkOps foreachChunkWhile
|
|
655
|
+
*/
|
|
656
|
+
|
|
657
|
+
|
|
658
|
+
export function makeForeachChunkWhile(f, __tsplusTrace) {
|
|
659
|
+
const reader = tsplus_module_4.readWith(inp => tsplus_module_5.flatMap_(tsplus_module_4.fromIO(() => f(inp)), cont => cont ? reader : tsplus_module_4.unit), tsplus_module_4.failNow, () => tsplus_module_4.unit);
|
|
660
|
+
return new tsplus_module_3.Sink(reader);
|
|
661
|
+
}
|
|
662
|
+
/**
|
|
663
|
+
* A sink that folds its inputs with the provided function, termination
|
|
664
|
+
* predicate and initial state.
|
|
665
|
+
*
|
|
666
|
+
* @tsplus static fncts.io.SinkOps fold
|
|
667
|
+
*/
|
|
668
|
+
|
|
669
|
+
function makeFold_1(z, contFn, f, __tsplusTrace) {
|
|
670
|
+
return defer_1(() => new tsplus_module_3.Sink(foldReader(z(), contFn, f)), __tsplusTrace);
|
|
671
|
+
}
|
|
672
|
+
/**
|
|
673
|
+
* @tsplus tailRec
|
|
674
|
+
*/
|
|
675
|
+
|
|
676
|
+
|
|
677
|
+
function foldChunkSplit(contFn, f, s, chunk, idx, len) {
|
|
678
|
+
var contFn_1 = contFn,
|
|
679
|
+
f_1 = f,
|
|
680
|
+
s_1 = s,
|
|
681
|
+
chunk_1 = chunk,
|
|
682
|
+
idx_1 = idx,
|
|
683
|
+
len_1 = len;
|
|
684
|
+
var contFn_2 = contFn,
|
|
685
|
+
f_2 = f,
|
|
686
|
+
s_2 = s,
|
|
687
|
+
chunk_2 = chunk,
|
|
688
|
+
idx_2 = idx,
|
|
689
|
+
len_2 = len;
|
|
690
|
+
|
|
691
|
+
while (1) {
|
|
692
|
+
if (idx_1 === len_1) {
|
|
693
|
+
return [s_1, tsplus_module_1.empty()];
|
|
694
|
+
} else {
|
|
695
|
+
const s1 = f_1(s_1, tsplus_module_2.unsafeGet_(chunk_1, idx_1));
|
|
696
|
+
|
|
697
|
+
if (contFn_1(s1)) {
|
|
698
|
+
contFn_2 = contFn_1;
|
|
699
|
+
f_2 = f_1;
|
|
700
|
+
s_2 = s1;
|
|
701
|
+
chunk_2 = chunk_1;
|
|
702
|
+
idx_2 = idx_1 + 1;
|
|
703
|
+
len_2 = len_1;
|
|
704
|
+
contFn_1 = contFn_2;
|
|
705
|
+
f_1 = f_2;
|
|
706
|
+
s_1 = s_2;
|
|
707
|
+
chunk_1 = chunk_2;
|
|
708
|
+
idx_1 = idx_2;
|
|
709
|
+
len_1 = len_2;
|
|
710
|
+
continue;
|
|
711
|
+
} else {
|
|
712
|
+
return [s1, tsplus_module_2.drop_(chunk_1, idx_1 + 1)];
|
|
713
|
+
}
|
|
714
|
+
}
|
|
715
|
+
}
|
|
716
|
+
}
|
|
717
|
+
|
|
718
|
+
function foldReader(s, contFn, f) {
|
|
719
|
+
if (!contFn(s)) {
|
|
720
|
+
return tsplus_module_5.succeedNow(s);
|
|
721
|
+
} else {
|
|
722
|
+
return tsplus_module_4.readWith(inp => {
|
|
723
|
+
const [nextS, leftovers] = foldChunkSplit(contFn, f, s, inp, 0, inp.length);
|
|
724
|
+
|
|
725
|
+
if (tsplus_module_2.isNonEmpty(leftovers)) {
|
|
726
|
+
return tsplus_module_4.as_(tsplus_module_4.writeNow(leftovers), () => nextS);
|
|
727
|
+
} else {
|
|
728
|
+
return foldReader(nextS, contFn, f);
|
|
729
|
+
}
|
|
730
|
+
}, _ => tsplus_module_4.failNow(_), _ => tsplus_module_5.succeedNow(_));
|
|
731
|
+
}
|
|
732
|
+
}
|
|
733
|
+
/**
|
|
734
|
+
* Creates a sink that folds elements of type `In` into a structure of type
|
|
735
|
+
* `S` until `max` elements have been folded.
|
|
736
|
+
*
|
|
737
|
+
* Like {@link foldWeighted}, but with a constant cost function of 1.
|
|
738
|
+
*
|
|
739
|
+
* @tsplus static fncts.io.SinkOps foldUntil
|
|
740
|
+
*/
|
|
741
|
+
|
|
742
|
+
|
|
743
|
+
function makeFoldUntil_1(z, max, f, __tsplusTrace) {
|
|
744
|
+
return unwrap_1(() => tsplus_module_9.map_(tsplus_module_9.succeed(max, __tsplusTrace), max => map_1(makeFold_1(() => [z(), 0], ([_, n]) => n < max, ([o, count], i) => [f(o, i), count + 1], __tsplusTrace), ([s]) => s, __tsplusTrace), __tsplusTrace));
|
|
745
|
+
}
|
|
746
|
+
/**
|
|
747
|
+
* A sink that folds its input chunks with the provided function, termination
|
|
748
|
+
* predicate and initial state. `contFn` condition is checked only for the
|
|
749
|
+
* initial value and at the end of processing of each chunk. `f` and `contFn`
|
|
750
|
+
* must preserve chunking-invariance.
|
|
751
|
+
*
|
|
752
|
+
* @tsplus static fncts.io.SinkOps foldChunks
|
|
753
|
+
*/
|
|
754
|
+
|
|
755
|
+
|
|
756
|
+
function makeFoldChunks_1(z, contFn, f, __tsplusTrace) {
|
|
757
|
+
return defer_1(() => new tsplus_module_3.Sink(foldChunksReader(z(), contFn, f)), __tsplusTrace);
|
|
758
|
+
}
|
|
759
|
+
|
|
760
|
+
function foldChunksReader(s, contFn, f) {
|
|
761
|
+
if (!contFn(s)) {
|
|
762
|
+
return tsplus_module_5.succeedNow(s);
|
|
763
|
+
} else {
|
|
764
|
+
return tsplus_module_4.readWith(inp => {
|
|
765
|
+
const nextS = f(s, inp);
|
|
766
|
+
return foldChunksReader(nextS, contFn, f);
|
|
767
|
+
}, err => tsplus_module_4.failNow(err), _ => tsplus_module_5.succeedNow(_));
|
|
768
|
+
}
|
|
769
|
+
}
|
|
770
|
+
/**
|
|
771
|
+
* A sink that effectfully folds its input chunks with the provided function,
|
|
772
|
+
* termination predicate and initial state. `contFn` condition is checked only
|
|
773
|
+
* for the initial value and at the end of processing of each chunk. `f` and
|
|
774
|
+
* `contFn` must preserve chunking-invariance.
|
|
775
|
+
*
|
|
776
|
+
* @tsplus static fncts.io.SinkOps foldChunksIO
|
|
777
|
+
*/
|
|
778
|
+
|
|
779
|
+
|
|
780
|
+
function makeFoldChunksIO_1(z, contFn, f, __tsplusTrace) {
|
|
781
|
+
return defer_1(() => new tsplus_module_3.Sink(foldChunksIOReader(z(), contFn, f)), __tsplusTrace);
|
|
782
|
+
}
|
|
783
|
+
|
|
784
|
+
function foldChunksIOReader(s, contFn, f) {
|
|
785
|
+
if (!contFn(s)) {
|
|
786
|
+
return tsplus_module_5.succeedNow(s);
|
|
787
|
+
} else {
|
|
788
|
+
return tsplus_module_4.readWith(inp => tsplus_module_5.flatMap_(tsplus_module_4.fromIO(() => f(s, inp)), s => foldChunksIOReader(s, contFn, f)), err => tsplus_module_4.failNow(err), _ => tsplus_module_5.succeedNow(_));
|
|
789
|
+
}
|
|
790
|
+
}
|
|
791
|
+
/**
|
|
792
|
+
* A sink that folds its inputs with the provided function and initial state.
|
|
793
|
+
*
|
|
794
|
+
* @tsplus static fncts.io.SinkOps foldLeft
|
|
795
|
+
*/
|
|
796
|
+
|
|
797
|
+
|
|
798
|
+
function makeFoldLeft_1(z, f) {
|
|
799
|
+
return ignoreLeftover_1(makeFold_1(z, () => true, f, fileName_1 + ":1006:19"), fileName_1 + ":1006:37");
|
|
800
|
+
}
|
|
801
|
+
/**
|
|
802
|
+
* A sink that folds its input chunks with the provided function and initial
|
|
803
|
+
* state. `f` must preserve chunking-invariance.
|
|
804
|
+
*
|
|
805
|
+
* @tsplus static fncts.io.SinkOps foldLeftChunks
|
|
806
|
+
*/
|
|
807
|
+
|
|
808
|
+
|
|
809
|
+
export function makeFoldLeftChunks(z, f) {
|
|
810
|
+
return ignoreLeftover_1(makeFoldChunks_1(z, () => true, f, fileName_1 + ":1019:25"), fileName_1 + ":1019:43");
|
|
811
|
+
}
|
|
812
|
+
/**
|
|
813
|
+
* A sink that effectfully folds its input chunks with the provided function
|
|
814
|
+
* and initial state. `f` must preserve chunking-invariance.
|
|
815
|
+
*
|
|
816
|
+
* @tsplus static fncts.io.SinkOps foldLeftChunksIO
|
|
817
|
+
*/
|
|
818
|
+
|
|
819
|
+
export function makeFoldLeftChunksIO(z, f, __tsplusTrace) {
|
|
820
|
+
return makeFoldChunksIO_1(z, () => true, f, __tsplusTrace);
|
|
821
|
+
}
|
|
822
|
+
/**
|
|
823
|
+
* A sink that effectfully folds its inputs with the provided function and
|
|
824
|
+
* initial state.
|
|
825
|
+
*
|
|
826
|
+
* @tsplus static fncts.io.SinkOps foldLeftIO
|
|
827
|
+
*/
|
|
828
|
+
|
|
829
|
+
export function makeFoldLeftIO(z, f, __tsplusTrace) {
|
|
830
|
+
return makeFoldIO_1(z, () => true, f);
|
|
831
|
+
}
|
|
832
|
+
/**
|
|
833
|
+
* A sink that effectfully folds its inputs with the provided function,
|
|
834
|
+
* termination predicate and initial state.
|
|
835
|
+
*
|
|
836
|
+
* @tsplus static fncts.io.SinkOps foldIO
|
|
837
|
+
*/
|
|
838
|
+
|
|
839
|
+
function makeFoldIO_1(z, contFn, f) {
|
|
840
|
+
return defer_1(() => new tsplus_module_3.Sink(foldIOReader(z(), contFn, f)), fileName_1 + ":1061:20");
|
|
841
|
+
}
|
|
842
|
+
|
|
843
|
+
function foldChunkSplitIO(s, contFn, f, chunk, idx, len) {
|
|
844
|
+
if (idx === len) {
|
|
845
|
+
return tsplus_module_9.succeedNow([s, tsplus_module_16.nothing()], fileName_1 + ":1073:25");
|
|
846
|
+
} else {
|
|
847
|
+
return tsplus_module_9.flatMap_(f(s, tsplus_module_2.unsafeGet_(chunk, idx)), s1 => {
|
|
848
|
+
if (contFn(s1)) {
|
|
849
|
+
return foldChunkSplitIO(s1, contFn, f, chunk, idx + 1, len);
|
|
850
|
+
} else {
|
|
851
|
+
return tsplus_module_9.succeedNow([s1, tsplus_module_16.just(tsplus_module_2.drop_(chunk, idx + 1))], fileName_1 + ":1079:29");
|
|
852
|
+
}
|
|
853
|
+
}, fileName_1 + ":1075:36");
|
|
854
|
+
}
|
|
855
|
+
}
|
|
856
|
+
|
|
857
|
+
function foldIOReader(s, contFn, f) {
|
|
858
|
+
if (!contFn(s)) {
|
|
859
|
+
return tsplus_module_5.succeedNow(s);
|
|
860
|
+
} else {
|
|
861
|
+
return tsplus_module_4.readWith(inp => tsplus_module_5.flatMap_(tsplus_module_4.fromIO(() => foldChunkSplitIO(s, contFn, f, inp, 0, inp.length)), ([nextS, leftovers]) => tsplus_module_22.match_(leftovers, () => foldIOReader(nextS, contFn, f), l => tsplus_module_4.as_(tsplus_module_4.writeNow(l), () => nextS))), err => tsplus_module_4.failNow(err), _ => tsplus_module_5.succeedNow(_));
|
|
862
|
+
}
|
|
863
|
+
}
|
|
864
|
+
/**
|
|
865
|
+
* Creates a sink that effectfully folds elements of type `In` into a
|
|
866
|
+
* structure of type `S` until `max` elements have been folded.
|
|
867
|
+
*
|
|
868
|
+
* Like {@link makeFoldWeightedIO}, but with a constant cost function of 1.
|
|
869
|
+
*
|
|
870
|
+
* @tsplus static fncts.io.SinkOps foldUntilIO
|
|
871
|
+
*/
|
|
872
|
+
|
|
873
|
+
|
|
874
|
+
export function makeFoldUntilIO(z, max, f, __tsplusTrace) {
|
|
875
|
+
return map_1(makeFoldIO_1(() => [z(), 0], ([_, n]) => n < max(), ([o, count], i) => tsplus_module_9.map_(f(o, i), s => [s, count + 1], __tsplusTrace)), ([s]) => s, __tsplusTrace);
|
|
876
|
+
}
|
|
877
|
+
/**
|
|
878
|
+
* Creates a sink that folds elements of type `In` into a structure of type
|
|
879
|
+
* `S`, until `max` worth of elements (determined by the `costFn`) have been
|
|
880
|
+
* folded.
|
|
881
|
+
*
|
|
882
|
+
* The `decompose` function will be used for decomposing elements that cause
|
|
883
|
+
* an `S` aggregate to cross `max` into smaller elements.
|
|
884
|
+
*
|
|
885
|
+
*
|
|
886
|
+
* Be vigilant with this function, it has to generate "simpler" values or the
|
|
887
|
+
* fold may never end. A value is considered indivisible if `decompose` yields
|
|
888
|
+
* the empty chunk or a single-valued chunk. In these cases, there is no other
|
|
889
|
+
* choice than to yield a value that will cross the threshold.
|
|
890
|
+
*
|
|
891
|
+
* The {@link makeFoldWeightedDecomposeIO} allows the decompose function to return a
|
|
892
|
+
* `IO` value, and consequently it allows the sink to fail.
|
|
893
|
+
*
|
|
894
|
+
* @tsplus static fncts.io.SinkOps foldWeightedDecompose
|
|
895
|
+
*/
|
|
896
|
+
|
|
897
|
+
function makeFoldWeightedDecompose_1(z, costFn, max, decompose, f, __tsplusTrace) {
|
|
898
|
+
return defer_1(() => {
|
|
899
|
+
/**
|
|
900
|
+
* @tsplus tailRec
|
|
901
|
+
*/
|
|
902
|
+
function fold(inp, s, max, dirty, cost, idx) {
|
|
903
|
+
if (idx === inp.length) {
|
|
904
|
+
return [s, cost, dirty, tsplus_module_1.empty()];
|
|
905
|
+
} else {
|
|
906
|
+
const elem = tsplus_module_2.unsafeGet_(inp, idx);
|
|
907
|
+
const total = cost + costFn(s, elem);
|
|
908
|
+
|
|
909
|
+
if (total <= max) {
|
|
910
|
+
return fold(inp, f(s, elem), max, true, total, idx + 1);
|
|
911
|
+
} else {
|
|
912
|
+
const decomposed = decompose(elem);
|
|
913
|
+
|
|
914
|
+
if (decomposed.length <= 1 && !dirty) {
|
|
915
|
+
return [f(s, elem), total, true, tsplus_module_2.drop_(inp, idx + 1)];
|
|
916
|
+
} else if (decomposed.length <= 1 && dirty) {
|
|
917
|
+
return [s, cost, dirty, tsplus_module_2.drop_(inp, idx)];
|
|
918
|
+
} else {
|
|
919
|
+
return fold(tsplus_module_2.concat_(decomposed, tsplus_module_2.drop_(inp, idx + 1)), s, max, dirty, cost, 0);
|
|
920
|
+
}
|
|
921
|
+
}
|
|
922
|
+
}
|
|
923
|
+
}
|
|
924
|
+
|
|
925
|
+
function go(s, cost, dirty, max) {
|
|
926
|
+
return tsplus_module_4.readWith(inp => {
|
|
927
|
+
const [nextS, nextCost, nextDirty, leftovers] = fold(inp, s, max, dirty, cost, 0);
|
|
928
|
+
|
|
929
|
+
if (tsplus_module_2.isNonEmpty(leftovers)) {
|
|
930
|
+
return tsplus_module_5.apSecond_(tsplus_module_4.writeNow(leftovers), tsplus_module_5.succeedNow(nextS));
|
|
931
|
+
} else if (cost > max) {
|
|
932
|
+
return tsplus_module_5.succeedNow(nextS);
|
|
933
|
+
} else {
|
|
934
|
+
return go(nextS, nextCost, nextDirty, max);
|
|
935
|
+
}
|
|
936
|
+
}, err => tsplus_module_4.failNow(err), _ => tsplus_module_5.succeedNow(s));
|
|
937
|
+
}
|
|
938
|
+
|
|
939
|
+
return new tsplus_module_3.Sink(go(z(), 0, false, max()));
|
|
940
|
+
}, __tsplusTrace);
|
|
941
|
+
}
|
|
942
|
+
/**
|
|
943
|
+
* Creates a sink that effectfully folds elements of type `In` into a
|
|
944
|
+
* structure of type `S`, until `max` worth of elements (determined by the
|
|
945
|
+
* `costFn`) have been folded.
|
|
946
|
+
*
|
|
947
|
+
* The `decompose` function will be used for decomposing elements that cause
|
|
948
|
+
* an `S` aggregate to cross `max` into smaller elements. Be vigilant with
|
|
949
|
+
* this function, it has to generate "simpler" values or the fold may never
|
|
950
|
+
* end. A value is considered indivisible if `decompose` yields the empty
|
|
951
|
+
* chunk or a single-valued chunk. In these cases, there is no other choice
|
|
952
|
+
* than to yield a value that will cross the threshold.
|
|
953
|
+
*
|
|
954
|
+
* @tsplus static fncts.io.SinkOps foldWeightedDecomposeIO
|
|
955
|
+
*/
|
|
956
|
+
|
|
957
|
+
|
|
958
|
+
function makeFoldWeightedDecomposeIO_1(z, costFn, max, decompose, f, __tsplusTrace) {
|
|
959
|
+
return defer_1(() => {
|
|
960
|
+
function fold(inp, s, max, dirty, cost, idx) {
|
|
961
|
+
if (idx === inp.length) {
|
|
962
|
+
return tsplus_module_9.succeedNow([s, cost, dirty, tsplus_module_1.empty()], __tsplusTrace);
|
|
963
|
+
} else {
|
|
964
|
+
const elem = tsplus_module_2.unsafeGet_(inp, idx);
|
|
965
|
+
return tsplus_module_9.flatMap_(tsplus_module_9.map_(costFn(s, elem), _ => cost + _, __tsplusTrace), total => {
|
|
966
|
+
if (total <= max) {
|
|
967
|
+
return tsplus_module_9.flatMap_(f(s, elem), s => fold(inp, s, max, true, total, idx + 1), __tsplusTrace);
|
|
968
|
+
} else {
|
|
969
|
+
return tsplus_module_9.flatMap_(decompose(elem), decomposed => {
|
|
970
|
+
if (decomposed.length <= 1 && !dirty) {
|
|
971
|
+
return tsplus_module_9.map_(f(s, elem), s => [s, total, true, tsplus_module_2.drop_(inp, idx + 1)], __tsplusTrace);
|
|
972
|
+
} else if (decomposed.length <= 1 && dirty) {
|
|
973
|
+
return tsplus_module_9.succeedNow([s, cost, dirty, tsplus_module_2.drop_(inp, idx)], __tsplusTrace);
|
|
974
|
+
} else {
|
|
975
|
+
return fold(tsplus_module_2.concat_(decomposed, tsplus_module_2.drop_(inp, idx + 1)), s, max, dirty, cost, 0);
|
|
976
|
+
}
|
|
977
|
+
}, __tsplusTrace);
|
|
978
|
+
}
|
|
979
|
+
}, __tsplusTrace);
|
|
980
|
+
}
|
|
981
|
+
}
|
|
982
|
+
|
|
983
|
+
function go(s, cost, dirty, max) {
|
|
984
|
+
return tsplus_module_4.readWith(inp => tsplus_module_5.flatMap_(tsplus_module_4.fromIO(() => fold(inp, s, max, dirty, cost, 0)), ([nextS, nextCost, nextDirty, leftovers]) => {
|
|
985
|
+
if (tsplus_module_2.isNonEmpty(leftovers)) {
|
|
986
|
+
return tsplus_module_5.apSecond_(tsplus_module_4.writeNow(leftovers), tsplus_module_5.succeedNow(nextS));
|
|
987
|
+
} else if (cost > max) {
|
|
988
|
+
return tsplus_module_5.succeedNow(nextS);
|
|
989
|
+
} else {
|
|
990
|
+
return go(nextS, nextCost, nextDirty, max);
|
|
991
|
+
}
|
|
992
|
+
}), err => tsplus_module_4.failNow(err), _ => tsplus_module_5.succeedNow(s));
|
|
993
|
+
}
|
|
994
|
+
|
|
995
|
+
return new tsplus_module_3.Sink(go(z(), 0, false, max()));
|
|
996
|
+
}, __tsplusTrace);
|
|
997
|
+
}
|
|
998
|
+
/**
|
|
999
|
+
* Creates a sink that folds elements of type `In` into a structure of type
|
|
1000
|
+
* `S`, until `max` worth of elements (determined by the `costFn`) have been
|
|
1001
|
+
* folded.
|
|
1002
|
+
*
|
|
1003
|
+
* @note
|
|
1004
|
+
* Elements that have an individual cost larger than `max` will force the
|
|
1005
|
+
* sink to cross the `max` cost. See {@link makeFoldWeightedDecompose} for a variant
|
|
1006
|
+
* that can handle these cases.
|
|
1007
|
+
*
|
|
1008
|
+
* @tsplus static fncts.io.SinkOps foldWeighted
|
|
1009
|
+
*/
|
|
1010
|
+
|
|
1011
|
+
|
|
1012
|
+
export function makeFoldWeighted(z, costFn, max, f, __tsplusTrace) {
|
|
1013
|
+
return makeFoldWeightedDecompose_1(z, costFn, max, tsplus_module_24.single, f, __tsplusTrace);
|
|
1014
|
+
}
|
|
1015
|
+
/**
|
|
1016
|
+
* Creates a sink that effectfully folds elements of type `In` into a
|
|
1017
|
+
* structure of type `S`, until `max` worth of elements (determined by the
|
|
1018
|
+
* `costFn`) have been folded.
|
|
1019
|
+
*
|
|
1020
|
+
* @note
|
|
1021
|
+
* Elements that have an individual cost larger than `max` will force the
|
|
1022
|
+
* sink to cross the `max` cost. See {@link makeFoldWeightedDecomposeIO} for a
|
|
1023
|
+
* variant that can handle these cases.
|
|
1024
|
+
*
|
|
1025
|
+
* @tsplus static fncts.io.SinkOps foldWeightedIO
|
|
1026
|
+
*/
|
|
1027
|
+
|
|
1028
|
+
export function makeFoldWeightedIO(z, costFn, max, f, __tsplusTrace) {
|
|
1029
|
+
return makeFoldWeightedDecomposeIO_1(z, costFn, max, inp => tsplus_module_9.succeedNow(tsplus_module_24.single(inp), __tsplusTrace), f, __tsplusTrace);
|
|
1030
|
+
}
|
|
1031
|
+
/**
|
|
1032
|
+
* Transforms this sink's result.
|
|
1033
|
+
*
|
|
1034
|
+
* @tsplus fluent fncts.io.Sink map
|
|
1035
|
+
*/
|
|
1036
|
+
|
|
1037
|
+
function map_1(self, f, __tsplusTrace) {
|
|
1038
|
+
return new tsplus_module_3.Sink(tsplus_module_5.map_(self.channel, f));
|
|
1039
|
+
}
|
|
1040
|
+
/**
|
|
1041
|
+
* Transforms the errors emitted by this sink using `f`.
|
|
1042
|
+
*
|
|
1043
|
+
* @tsplus fluent fncts.io.Sink mapError
|
|
1044
|
+
*/
|
|
1045
|
+
|
|
1046
|
+
|
|
1047
|
+
export function mapError_(self, f, __tsplusTrace) {
|
|
1048
|
+
return new tsplus_module_3.Sink(tsplus_module_4.mapError_(self.channel, f));
|
|
1049
|
+
}
|
|
1050
|
+
/**
|
|
1051
|
+
* Effectfully transforms this sink's result.
|
|
1052
|
+
*
|
|
1053
|
+
* @tsplus fluent fncts.io.Sink mapIO
|
|
1054
|
+
*/
|
|
1055
|
+
|
|
1056
|
+
function mapIO_1(self, f, __tsplusTrace) {
|
|
1057
|
+
return new tsplus_module_3.Sink(tsplus_module_4.mapIO_(self.channel, f));
|
|
1058
|
+
}
|
|
1059
|
+
/**
|
|
1060
|
+
* Runs this sink until it yields a result, then uses that result to create
|
|
1061
|
+
* another sink from the provided function which will continue to run until it
|
|
1062
|
+
* yields a result.
|
|
1063
|
+
*
|
|
1064
|
+
* This function essentially runs sinks in sequence.
|
|
1065
|
+
*
|
|
1066
|
+
* @tsplus fluent fncts.io.Sink matchSink
|
|
1067
|
+
*/
|
|
1068
|
+
|
|
1069
|
+
|
|
1070
|
+
function matchSink_1(self, onFailure, onSuccess, __tsplusTrace) {
|
|
1071
|
+
return new tsplus_module_3.Sink(tsplus_module_4.matchChannel_(tsplus_module_4.doneCollect(self.channel), e => onFailure(e).channel, ([leftovers, z]) => tsplus_module_4.defer(() => {
|
|
1072
|
+
const leftoversRef = new AtomicReference(tsplus_module_2.filter_(leftovers, c => tsplus_module_2.isNonEmpty(c)));
|
|
1073
|
+
const refReader = tsplus_module_5.flatMap_(tsplus_module_5.succeed(() => leftoversRef.getAndSet(tsplus_module_1.empty())), chunk => tsplus_module_4.writeChunk(chunk));
|
|
1074
|
+
const passthrough = tsplus_module_4.id();
|
|
1075
|
+
const continuationSink = tsplus_module_4.pipeTo_(tsplus_module_5.apSecond_(refReader, passthrough), onSuccess(z).channel);
|
|
1076
|
+
return tsplus_module_5.flatMap_(tsplus_module_4.doneCollect(continuationSink), ([newLeftovers, z1]) => tsplus_module_5.apSecond_(tsplus_module_5.flatMap_(tsplus_module_5.succeed(() => leftoversRef.get), tsplus_module_4.writeChunk), tsplus_module_4.as_(tsplus_module_4.writeChunk(newLeftovers), () => z1)));
|
|
1077
|
+
})));
|
|
1078
|
+
}
|
|
1079
|
+
/**
|
|
1080
|
+
* Switch to another sink in case of failure
|
|
1081
|
+
*
|
|
1082
|
+
* @tsplus fluent fncts.io.Sink orElse
|
|
1083
|
+
*/
|
|
1084
|
+
|
|
1085
|
+
|
|
1086
|
+
export function orElse(self, that, __tsplusTrace) {
|
|
1087
|
+
return defer_1(() => new tsplus_module_3.Sink(tsplus_module_4.orElse_(self.channel, that().channel)), __tsplusTrace);
|
|
1088
|
+
}
|
|
1089
|
+
/**
|
|
1090
|
+
* Provides the sink with its required environment, which eliminates its
|
|
1091
|
+
* dependency on `R`.
|
|
1092
|
+
*
|
|
1093
|
+
* @tsplus fluent fncts.io.Sink provideEnvironment
|
|
1094
|
+
*/
|
|
1095
|
+
|
|
1096
|
+
export function provideEnvironment(self, r, __tsplusTrace) {
|
|
1097
|
+
return new tsplus_module_3.Sink(tsplus_module_4.provideEnvironment_(self.channel, r));
|
|
1098
|
+
}
|
|
1099
|
+
/**
|
|
1100
|
+
* Runs both sinks in parallel on the input, returning the result or the
|
|
1101
|
+
* error from the one that finishes first.
|
|
1102
|
+
*
|
|
1103
|
+
* @tsplus fluent fncts.io.Sink race
|
|
1104
|
+
*/
|
|
1105
|
+
|
|
1106
|
+
export function race(self, that, __tsplusTrace) {
|
|
1107
|
+
return map_1(raceBoth_1(self, that), result => tsplus_module_25.merge(result), __tsplusTrace);
|
|
1108
|
+
}
|
|
1109
|
+
/**
|
|
1110
|
+
* Runs both sinks in parallel on the input, returning the result or the error
|
|
1111
|
+
* from the one that finishes first.
|
|
1112
|
+
*
|
|
1113
|
+
* @tsplus fluent fncts.io.Sink raceBoth
|
|
1114
|
+
*/
|
|
1115
|
+
|
|
1116
|
+
function raceBoth_1(self, that, capacity = () => 16, __tsplusTrace) {
|
|
1117
|
+
return raceWith_1(self, that, selfDone => tsplus_module_27.done(tsplus_module_9.map_(tsplus_module_9.fromExitNow(selfDone, __tsplusTrace), tsplus_module_26.left, __tsplusTrace)), thatDone => tsplus_module_27.done(tsplus_module_9.map_(tsplus_module_9.fromExitNow(thatDone, __tsplusTrace), tsplus_module_26.right, __tsplusTrace)), capacity, __tsplusTrace);
|
|
1118
|
+
}
|
|
1119
|
+
/**
|
|
1120
|
+
* Runs both sinks in parallel on the input, using the specified merge
|
|
1121
|
+
* function as soon as one result or the other has been computed.
|
|
1122
|
+
*
|
|
1123
|
+
* @tsplus fluent fncts.io.Sink raceWith
|
|
1124
|
+
*/
|
|
1125
|
+
|
|
1126
|
+
|
|
1127
|
+
function raceWith_1(self, that, leftDone, rightDone, capacity = () => 16, __tsplusTrace) {
|
|
1128
|
+
const scoped = tsplus_module_9.defer(() => {
|
|
1129
|
+
const that0 = that();
|
|
1130
|
+
const capacity0 = capacity();
|
|
1131
|
+
return tsplus_module_9.flatMap_(tsplus_module_29.makeBounded(capacity()), hub => tsplus_module_9.flatMap_(tsplus_module_4.fromHubScoped(() => hub), c1 => tsplus_module_9.map_(tsplus_module_4.fromHubScoped(() => hub), c2 => {
|
|
1132
|
+
const reader = tsplus_module_4.toHub(() => hub);
|
|
1133
|
+
const writer = tsplus_module_28.mergeWith_(tsplus_module_4.pipeTo_(c1, self.channel), tsplus_module_4.pipeTo_(c2, that0.channel), leftDone, rightDone);
|
|
1134
|
+
const channel = tsplus_module_28.mergeWith_(reader, writer, () => tsplus_module_27.wait(tsplus_module_9.fromExitNow), done => tsplus_module_27.done(tsplus_module_9.fromExitNow(done, __tsplusTrace)));
|
|
1135
|
+
return new tsplus_module_3.Sink(channel);
|
|
1136
|
+
}, __tsplusTrace), __tsplusTrace), __tsplusTrace);
|
|
1137
|
+
}, __tsplusTrace);
|
|
1138
|
+
return unwrapScoped_1(() => scoped, __tsplusTrace);
|
|
1139
|
+
}
|
|
1140
|
+
/**
|
|
1141
|
+
* Accesses the specified service in the environment of the effect.
|
|
1142
|
+
*
|
|
1143
|
+
* @tsplus static fncts.io.SinkOps service
|
|
1144
|
+
*/
|
|
1145
|
+
|
|
1146
|
+
|
|
1147
|
+
export function service(
|
|
1148
|
+
/** @tsplus auto */
|
|
1149
|
+
tag) {
|
|
1150
|
+
const tag_1 = tag;
|
|
1151
|
+
return serviceWith_1(tsplus_module_14.identity, tag_1);
|
|
1152
|
+
}
|
|
1153
|
+
/**
|
|
1154
|
+
* Accesses the specified service in the environment of the sink.
|
|
1155
|
+
*
|
|
1156
|
+
* @tsplus static fncts.io.SinkOps serviceWith
|
|
1157
|
+
*/
|
|
1158
|
+
|
|
1159
|
+
function serviceWith_1(f,
|
|
1160
|
+
/** @tsplus auto */
|
|
1161
|
+
tag) {
|
|
1162
|
+
return fromIO_1(() => tsplus_module_13.serviceWith(f, tag), fileName_1 + ":1526:21");
|
|
1163
|
+
}
|
|
1164
|
+
/**
|
|
1165
|
+
* Accesses the specified service in the environment of the sink in the
|
|
1166
|
+
* context of an effect.
|
|
1167
|
+
*
|
|
1168
|
+
* @tsplus static fncts.io.SinkOps serviceWithIO
|
|
1169
|
+
*/
|
|
1170
|
+
|
|
1171
|
+
|
|
1172
|
+
export function serviceWithIO(f,
|
|
1173
|
+
/** @tsplus auto */
|
|
1174
|
+
tag) {
|
|
1175
|
+
return fromIO_1(() => tsplus_module_13.serviceWithIO(f, tag, fileName_1 + ":1539:38"), fileName_1 + ":1539:21");
|
|
1176
|
+
}
|
|
1177
|
+
/**
|
|
1178
|
+
* Accesses the specified service in the environment of the sink in the
|
|
1179
|
+
* context of a sink.
|
|
1180
|
+
*
|
|
1181
|
+
* @tsplus static fncts.io.SinkOps serviceWithSink
|
|
1182
|
+
*/
|
|
1183
|
+
|
|
1184
|
+
export function serviceWithSink(f,
|
|
1185
|
+
/** @tsplus auto */
|
|
1186
|
+
tag) {
|
|
1187
|
+
return new tsplus_module_3.Sink(tsplus_module_4.unwrap(() => tsplus_module_13.serviceWith(tsplus_module_14.compose_(f, s => s.channel), tag)));
|
|
1188
|
+
}
|
|
1189
|
+
/**
|
|
1190
|
+
* Splits the sink on the specified predicate, returning a new sink that
|
|
1191
|
+
* consumes elements until an element after the first satisfies the specified
|
|
1192
|
+
* predicate.
|
|
1193
|
+
*
|
|
1194
|
+
* @tsplus fluent fncts.io.Sink splitWhere
|
|
1195
|
+
*/
|
|
1196
|
+
|
|
1197
|
+
export function splitWhere(self, p, __tsplusTrace) {
|
|
1198
|
+
return new tsplus_module_3.Sink(tsplus_module_5.flatMap_(tsplus_module_4.fromIO(() => tsplus_module_8.make(() => tsplus_module_1.empty())), ref => tsplus_module_5.flatMap_(tsplus_module_4.collectElements(tsplus_module_4.pipeToOrFail_(splitter(p, false, ref), self.channel)), ([leftovers, z]) => tsplus_module_5.flatMap_(tsplus_module_4.fromIO(() => tsplus_module_7.get(ref)), leftover => tsplus_module_5.apSecond_(tsplus_module_4.writeNow(tsplus_module_2.concat_(leftover, tsplus_module_2.flatten(leftovers))), tsplus_module_5.succeedNow(z))))));
|
|
1199
|
+
}
|
|
1200
|
+
|
|
1201
|
+
function splitter(p, written, leftovers) {
|
|
1202
|
+
return tsplus_module_4.readWithCause(inp => {
|
|
1203
|
+
if (tsplus_module_2.isEmpty(inp)) {
|
|
1204
|
+
return splitter(p, written, leftovers);
|
|
1205
|
+
} else if (written) {
|
|
1206
|
+
const index = tsplus_module_30.findIndex(inp, p);
|
|
1207
|
+
|
|
1208
|
+
if (index === -1) {
|
|
1209
|
+
return tsplus_module_5.apSecond_(tsplus_module_4.writeNow(inp), splitter(p, true, leftovers));
|
|
1210
|
+
} else {
|
|
1211
|
+
const [left, right] = tsplus_module_2.splitAt_(inp, index);
|
|
1212
|
+
return tsplus_module_5.apSecond_(tsplus_module_4.writeNow(left), tsplus_module_4.fromIO(() => tsplus_module_6.set_(leftovers, right)));
|
|
1213
|
+
}
|
|
1214
|
+
} else {
|
|
1215
|
+
const index = tsplus_module_30.findIndex(inp, p);
|
|
1216
|
+
|
|
1217
|
+
if (index === -1) {
|
|
1218
|
+
return tsplus_module_5.apSecond_(tsplus_module_4.writeNow(inp), splitter(p, true, leftovers));
|
|
1219
|
+
} else {
|
|
1220
|
+
const [left, right] = tsplus_module_2.splitAt_(inp, Math.max(index, 1));
|
|
1221
|
+
return tsplus_module_5.apSecond_(tsplus_module_4.writeNow(left), tsplus_module_4.fromIO(() => tsplus_module_6.set_(leftovers, right)));
|
|
1222
|
+
}
|
|
1223
|
+
}
|
|
1224
|
+
}, tsplus_module_5.failCauseNow, tsplus_module_5.succeedNow);
|
|
1225
|
+
}
|
|
1226
|
+
/**
|
|
1227
|
+
* A sink that immediately ends with the specified value.
|
|
1228
|
+
*
|
|
1229
|
+
* @tsplus static fncts.io.SinkOps succeed
|
|
1230
|
+
*/
|
|
1231
|
+
|
|
1232
|
+
|
|
1233
|
+
export function succeed(z, __tsplusTrace) {
|
|
1234
|
+
return new tsplus_module_3.Sink(tsplus_module_5.succeed(z));
|
|
1235
|
+
}
|
|
1236
|
+
/**
|
|
1237
|
+
* A sink that immediately ends with the specified value.
|
|
1238
|
+
*
|
|
1239
|
+
* @tsplus static fncts.io.SinkOps succeedNow
|
|
1240
|
+
*/
|
|
1241
|
+
|
|
1242
|
+
export function succeedNow(z, __tsplusTrace) {
|
|
1243
|
+
return new tsplus_module_3.Sink(tsplus_module_5.succeedNow(z));
|
|
1244
|
+
}
|
|
1245
|
+
/**
|
|
1246
|
+
* Summarize a sink by running an effect when the sink starts and again when
|
|
1247
|
+
* it completes
|
|
1248
|
+
*
|
|
1249
|
+
* @tsplus fluent fncts.io.Sink summarized
|
|
1250
|
+
*/
|
|
1251
|
+
|
|
1252
|
+
function summarized_1(self, summary, f, __tsplusTrace) {
|
|
1253
|
+
return new tsplus_module_3.Sink(tsplus_module_4.unwrap(() => tsplus_module_9.map_(tsplus_module_9.succeed(summary, __tsplusTrace), summary => tsplus_module_5.flatMap_(tsplus_module_4.fromIO(() => summary), start => tsplus_module_5.flatMap_(self.channel, done => tsplus_module_5.map_(tsplus_module_4.fromIO(() => summary), end => [done, f(start, end)]))), __tsplusTrace)));
|
|
1254
|
+
}
|
|
1255
|
+
/**
|
|
1256
|
+
* @tsplus getter fncts.io.Sink timed
|
|
1257
|
+
*/
|
|
1258
|
+
|
|
1259
|
+
|
|
1260
|
+
export function timed(self, __tsplusTrace) {
|
|
1261
|
+
return summarized_1(self, () => tsplus_module_31.currentTime, (start, end) => tsplus_module_32.fromInterval(start, end), __tsplusTrace);
|
|
1262
|
+
}
|
|
1263
|
+
/**
|
|
1264
|
+
* Creates a sink produced from an effect.
|
|
1265
|
+
*
|
|
1266
|
+
* @tsplus static fncts.io.SinkOps unwrap
|
|
1267
|
+
*/
|
|
1268
|
+
|
|
1269
|
+
function unwrap_1(io) {
|
|
1270
|
+
return new tsplus_module_3.Sink(tsplus_module_4.unwrap(() => tsplus_module_9.map_(io(), sink => sink.channel, fileName_1 + ":1678:42")));
|
|
1271
|
+
}
|
|
1272
|
+
/**
|
|
1273
|
+
* Creates a sink produced from a scoped effect.
|
|
1274
|
+
*
|
|
1275
|
+
* @tsplus static fncts.io.SinkOps unwrapScoped
|
|
1276
|
+
*/
|
|
1277
|
+
|
|
1278
|
+
|
|
1279
|
+
function unwrapScoped_1(scoped, __tsplusTrace) {
|
|
1280
|
+
return new tsplus_module_3.Sink(tsplus_module_4.unwrapScoped(() => tsplus_module_9.map_(scoped(), sink => sink.channel, __tsplusTrace)));
|
|
1281
|
+
}
|
|
1282
|
+
/**
|
|
1283
|
+
* Feeds inputs to this sink until it yields a result, then switches over to
|
|
1284
|
+
* the provided sink until it yields a result, finally combining the two
|
|
1285
|
+
* results into a tuple.
|
|
1286
|
+
*
|
|
1287
|
+
* @tsplus fluent fncts.io.Sink zip
|
|
1288
|
+
*/
|
|
1289
|
+
|
|
1290
|
+
|
|
1291
|
+
export function zip(self, that, __tsplusTrace) {
|
|
1292
|
+
return zipWith_1(() => self, that, tsplus_module_14.tuple, __tsplusTrace);
|
|
1293
|
+
}
|
|
1294
|
+
/**
|
|
1295
|
+
* Runs both sinks in parallel on the input and combines the results in a
|
|
1296
|
+
* tuple.
|
|
1297
|
+
*
|
|
1298
|
+
* @tsplus fluent fncts.io.Sink zipC
|
|
1299
|
+
*/
|
|
1300
|
+
|
|
1301
|
+
export function zipC(self, that, __tsplusTrace) {
|
|
1302
|
+
return zipWithC_1(() => self, that, tsplus_module_14.tuple, __tsplusTrace);
|
|
1303
|
+
}
|
|
1304
|
+
/**
|
|
1305
|
+
* Feeds inputs to this sink until it yields a result, then switches over to
|
|
1306
|
+
* the provided sink until it yields a result, finally combining the two
|
|
1307
|
+
* results with `f`.
|
|
1308
|
+
*
|
|
1309
|
+
* @tsplus fluent fncts.io.Sink zipWith
|
|
1310
|
+
*/
|
|
1311
|
+
|
|
1312
|
+
function zipWith_1(self, that, f, __tsplusTrace) {
|
|
1313
|
+
return defer_1(() => flatMap_1(self(), z => map_1(that(), z1 => f(z, z1), __tsplusTrace), __tsplusTrace), __tsplusTrace);
|
|
1314
|
+
}
|
|
1315
|
+
/**
|
|
1316
|
+
* Runs both sinks in parallel on the input and combines the results using the
|
|
1317
|
+
* provided function.
|
|
1318
|
+
*
|
|
1319
|
+
* @tsplus fluent fncts.io.Sink zipWithC
|
|
69
1320
|
*/
|
|
70
1321
|
|
|
71
1322
|
|
|
72
|
-
function
|
|
73
|
-
|
|
74
|
-
return new tsplus_module_4.Sink(process);
|
|
1323
|
+
function zipWithC_1(self, that, f, __tsplusTrace) {
|
|
1324
|
+
return defer_1(() => raceWith_1(self(), () => that(), exit => tsplus_module_33.match_(exit, err => tsplus_module_27.done(tsplus_module_9.failCauseNow(err, __tsplusTrace)), lz => tsplus_module_27.wait(exit => tsplus_module_33.match_(exit, cause => tsplus_module_9.failCauseNow(cause, __tsplusTrace), rz => tsplus_module_9.succeedNow(f(lz, rz), __tsplusTrace)))), exit => tsplus_module_33.match_(exit, err => tsplus_module_27.done(tsplus_module_9.failCauseNow(err, __tsplusTrace)), rz => tsplus_module_27.wait(exit => tsplus_module_33.match_(exit, cause => tsplus_module_9.failCauseNow(cause, __tsplusTrace), lz => tsplus_module_9.succeedNow(f(lz, rz), __tsplusTrace))))), __tsplusTrace);
|
|
75
1325
|
}
|
|
76
1326
|
//# sourceMappingURL=api.mjs.map
|