firefly-compiler 0.4.4 → 0.4.6

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.
Files changed (98) hide show
  1. package/.hintrc +5 -0
  2. package/README.md +42 -61
  3. package/compiler/Compiler.ff +6 -2
  4. package/compiler/Deriver.ff +10 -0
  5. package/compiler/Environment.ff +2 -1
  6. package/compiler/JsEmitter.ff +29 -17
  7. package/compiler/Resolver.ff +1 -1
  8. package/core/.firefly/package.ff +1 -2
  9. package/core/Box.ff +7 -0
  10. package/core/BuildSystem.ff +5 -4
  11. package/core/Core.ff +4 -0
  12. package/core/HttpClient.ff +1 -1
  13. package/core/JsValue.ff +22 -1
  14. package/core/Lock.ff +4 -4
  15. package/core/NodeSystem.ff +12 -3
  16. package/core/Path.ff +1 -1
  17. package/core/SourceLocation.ff +41 -0
  18. package/core/Stack.ff +6 -6
  19. package/core/StringMap.ff +3 -3
  20. package/lsp/LanguageServer.ff +32 -7
  21. package/lsp/stderr.txt +1 -0
  22. package/lsp/stdin.txt +11 -0
  23. package/lsp/stdout.txt +41 -0
  24. package/lux/.firefly/package.ff +2 -0
  25. package/lux/Lux.ff +473 -0
  26. package/lux/LuxEvent.ff +116 -0
  27. package/lux/Main.ff +126 -0
  28. package/lux/Main2.ff +144 -0
  29. package/meetup/AutoCompletion.ff +6 -0
  30. package/output/js/ff/compiler/Builder.mjs +444 -440
  31. package/output/js/ff/compiler/Compiler.mjs +416 -410
  32. package/output/js/ff/compiler/Dependencies.mjs +389 -385
  33. package/output/js/ff/compiler/Deriver.mjs +1170 -1166
  34. package/output/js/ff/compiler/Dictionaries.mjs +1309 -1305
  35. package/output/js/ff/compiler/Environment.mjs +1015 -1005
  36. package/output/js/ff/compiler/Inference.mjs +4268 -4264
  37. package/output/js/ff/compiler/JsEmitter.mjs +5391 -5353
  38. package/output/js/ff/compiler/JsImporter.mjs +266 -262
  39. package/output/js/ff/compiler/LspHook.mjs +793 -789
  40. package/output/js/ff/compiler/Main.mjs +1699 -1695
  41. package/output/js/ff/compiler/Parser.mjs +4008 -4004
  42. package/output/js/ff/compiler/Patterns.mjs +927 -923
  43. package/output/js/ff/compiler/Resolver.mjs +2307 -2303
  44. package/output/js/ff/compiler/Substitution.mjs +1150 -1146
  45. package/output/js/ff/compiler/Syntax.mjs +12434 -12430
  46. package/output/js/ff/compiler/Token.mjs +3096 -3092
  47. package/output/js/ff/compiler/Tokenizer.mjs +593 -589
  48. package/output/js/ff/compiler/Unification.mjs +1752 -1748
  49. package/output/js/ff/compiler/Wildcards.mjs +608 -604
  50. package/output/js/ff/compiler/Workspace.mjs +687 -683
  51. package/output/js/ff/core/Any.mjs +143 -139
  52. package/output/js/ff/core/Array.mjs +547 -543
  53. package/output/js/ff/core/AssetSystem.mjs +274 -270
  54. package/output/js/ff/core/Atomic.mjs +154 -150
  55. package/output/js/ff/core/Bool.mjs +152 -141
  56. package/output/js/ff/core/Box.mjs +112 -0
  57. package/output/js/ff/core/BrowserSystem.mjs +126 -122
  58. package/output/js/ff/core/Buffer.mjs +395 -391
  59. package/output/js/ff/core/BuildSystem.mjs +296 -290
  60. package/output/js/ff/core/Channel.mjs +189 -185
  61. package/output/js/ff/core/Char.mjs +149 -145
  62. package/output/js/ff/core/Core.mjs +300 -288
  63. package/output/js/ff/core/Duration.mjs +116 -112
  64. package/output/js/ff/core/Equal.mjs +179 -175
  65. package/output/js/ff/core/Error.mjs +142 -138
  66. package/output/js/ff/core/FileHandle.mjs +150 -146
  67. package/output/js/ff/core/Float.mjs +225 -214
  68. package/output/js/ff/core/HttpClient.mjs +190 -186
  69. package/output/js/ff/core/Instant.mjs +109 -105
  70. package/output/js/ff/core/Int.mjs +265 -254
  71. package/output/js/ff/core/IntMap.mjs +280 -276
  72. package/output/js/ff/core/JsSystem.mjs +238 -234
  73. package/output/js/ff/core/JsValue.mjs +714 -664
  74. package/output/js/ff/core/List.mjs +2334 -2321
  75. package/output/js/ff/core/Lock.mjs +230 -226
  76. package/output/js/ff/core/Log.mjs +163 -159
  77. package/output/js/ff/core/Map.mjs +362 -358
  78. package/output/js/ff/core/NodeSystem.mjs +302 -283
  79. package/output/js/ff/core/Nothing.mjs +104 -100
  80. package/output/js/ff/core/Option.mjs +1015 -1002
  81. package/output/js/ff/core/Ordering.mjs +730 -726
  82. package/output/js/ff/core/Pair.mjs +331 -318
  83. package/output/js/ff/core/Path.mjs +546 -542
  84. package/output/js/ff/core/RbMap.mjs +1940 -1936
  85. package/output/js/ff/core/Serializable.mjs +428 -424
  86. package/output/js/ff/core/Set.mjs +254 -250
  87. package/output/js/ff/core/Show.mjs +205 -201
  88. package/output/js/ff/core/SourceLocation.mjs +229 -0
  89. package/output/js/ff/core/Stack.mjs +541 -537
  90. package/output/js/ff/core/Stream.mjs +1304 -1300
  91. package/output/js/ff/core/String.mjs +365 -354
  92. package/output/js/ff/core/StringMap.mjs +280 -276
  93. package/output/js/ff/core/Task.mjs +320 -316
  94. package/output/js/ff/core/Try.mjs +507 -503
  95. package/output/js/ff/core/Unit.mjs +151 -103
  96. package/package.json +29 -29
  97. package/vscode/package-lock.json +5 -5
  98. package/vscode/package.json +1 -1
@@ -1,1300 +1,1304 @@
1
-
2
-
3
- import * as ff_core_Any from "../../ff/core/Any.mjs"
4
-
5
- import * as ff_core_Array from "../../ff/core/Array.mjs"
6
-
7
- import * as ff_core_AssetSystem from "../../ff/core/AssetSystem.mjs"
8
-
9
- import * as ff_core_Atomic from "../../ff/core/Atomic.mjs"
10
-
11
- import * as ff_core_Bool from "../../ff/core/Bool.mjs"
12
-
13
- import * as ff_core_BrowserSystem from "../../ff/core/BrowserSystem.mjs"
14
-
15
- import * as ff_core_Buffer from "../../ff/core/Buffer.mjs"
16
-
17
- import * as ff_core_BuildSystem from "../../ff/core/BuildSystem.mjs"
18
-
19
- import * as ff_core_Channel from "../../ff/core/Channel.mjs"
20
-
21
- import * as ff_core_Char from "../../ff/core/Char.mjs"
22
-
23
- import * as ff_core_Core from "../../ff/core/Core.mjs"
24
-
25
- import * as ff_core_Duration from "../../ff/core/Duration.mjs"
26
-
27
- import * as ff_core_Equal from "../../ff/core/Equal.mjs"
28
-
29
- import * as ff_core_Error from "../../ff/core/Error.mjs"
30
-
31
- import * as ff_core_FileHandle from "../../ff/core/FileHandle.mjs"
32
-
33
- import * as ff_core_Float from "../../ff/core/Float.mjs"
34
-
35
- import * as ff_core_HttpClient from "../../ff/core/HttpClient.mjs"
36
-
37
- import * as ff_core_Instant from "../../ff/core/Instant.mjs"
38
-
39
- import * as ff_core_Int from "../../ff/core/Int.mjs"
40
-
41
- import * as ff_core_IntMap from "../../ff/core/IntMap.mjs"
42
-
43
- import * as ff_core_JsSystem from "../../ff/core/JsSystem.mjs"
44
-
45
- import * as ff_core_JsValue from "../../ff/core/JsValue.mjs"
46
-
47
- import * as ff_core_List from "../../ff/core/List.mjs"
48
-
49
- import * as ff_core_Lock from "../../ff/core/Lock.mjs"
50
-
51
- import * as ff_core_Log from "../../ff/core/Log.mjs"
52
-
53
- import * as ff_core_Map from "../../ff/core/Map.mjs"
54
-
55
- import * as ff_core_NodeSystem from "../../ff/core/NodeSystem.mjs"
56
-
57
- import * as ff_core_Nothing from "../../ff/core/Nothing.mjs"
58
-
59
- import * as ff_core_Option from "../../ff/core/Option.mjs"
60
-
61
- import * as ff_core_Ordering from "../../ff/core/Ordering.mjs"
62
-
63
- import * as ff_core_Pair from "../../ff/core/Pair.mjs"
64
-
65
- import * as ff_core_Path from "../../ff/core/Path.mjs"
66
-
67
- import * as ff_core_Serializable from "../../ff/core/Serializable.mjs"
68
-
69
- import * as ff_core_Set from "../../ff/core/Set.mjs"
70
-
71
- import * as ff_core_Show from "../../ff/core/Show.mjs"
72
-
73
- import * as ff_core_Stack from "../../ff/core/Stack.mjs"
74
-
75
- import * as ff_core_Stream from "../../ff/core/Stream.mjs"
76
-
77
- import * as ff_core_String from "../../ff/core/String.mjs"
78
-
79
- import * as ff_core_StringMap from "../../ff/core/StringMap.mjs"
80
-
81
- import * as ff_core_Task from "../../ff/core/Task.mjs"
82
-
83
- import * as ff_core_Try from "../../ff/core/Try.mjs"
84
-
85
- import * as ff_core_Unit from "../../ff/core/Unit.mjs"
86
-
87
- // type Stream
88
- export function Stream(next_, close_) {
89
- return {next_, close_};
90
- }
91
-
92
-
93
-
94
- export function make_(next_, close_ = (() => {
95
-
96
- })) {
97
- return ff_core_Stream.Stream(next_, close_)
98
- }
99
-
100
- export function init_(body_) {
101
- let initialized_ = false;
102
- let stream_ = ff_core_Stream.Stream((() => {
103
- return ff_core_Option.None()
104
- }), (() => {
105
-
106
- }));
107
- return ff_core_Stream.Stream((() => {
108
- if(initialized_) {
109
- return stream_.next_()
110
- } else {
111
- initialized_ = true;
112
- stream_ = body_();
113
- return stream_.next_()
114
- }
115
- }), (() => {
116
- initialized_ = true;
117
- stream_.close_()
118
- }))
119
- }
120
-
121
- export async function make_$(next_, close_ = (async ($task) => {
122
-
123
- }), $task) {
124
- return ff_core_Stream.Stream(next_, close_)
125
- }
126
-
127
- export async function init_$(body_, $task) {
128
- let initialized_ = false;
129
- let stream_ = ff_core_Stream.Stream((async ($task) => {
130
- return ff_core_Option.None()
131
- }), (async ($task) => {
132
-
133
- }));
134
- return ff_core_Stream.Stream((async ($task) => {
135
- if(initialized_) {
136
- return (await stream_.next_($task))
137
- } else {
138
- initialized_ = true;
139
- stream_ = (await body_($task));
140
- return (await stream_.next_($task))
141
- }
142
- }), (async ($task) => {
143
- initialized_ = true;
144
- (await stream_.close_($task))
145
- }))
146
- }
147
-
148
- export function Stream_addAll(self_, that_) {
149
- let firstDone_ = false;
150
- return ff_core_Stream.Stream((() => {
151
- if(firstDone_) {
152
- return that_.next_()
153
- } else {
154
- return ff_core_Option.Option_orElse(self_.next_(), (() => {
155
- firstDone_ = true;
156
- return that_.next_()
157
- }))
158
- }
159
- }), (() => {
160
- try {
161
- self_.close_()
162
- } finally {
163
- that_.close_()
164
- }
165
- }))
166
- }
167
-
168
- export function Stream_map(self_, body_) {
169
- return ff_core_Stream.Stream((() => {
170
- return ff_core_Option.Option_map(self_.next_(), body_)
171
- }), (() => {
172
- self_.close_()
173
- }))
174
- }
175
-
176
- export function Stream_flatMap(self_, body_) {
177
- let inner_ = ff_core_Stream.Stream((() => {
178
- return ff_core_Option.None()
179
- }), (() => {
180
-
181
- }));
182
- return ff_core_Stream.Stream((() => {
183
- let result_ = ff_core_Option.None();
184
- while(ff_core_Option.Option_isEmpty(result_)) {
185
- do {
186
- const _1 = inner_.next_();
187
- {
188
- const i_ = _1;
189
- if(_1.Some) {
190
- result_ = ff_core_Option.Some(i_)
191
- break
192
- }
193
- }
194
- {
195
- if(_1.None) {
196
- do {
197
- const _1 = self_.next_();
198
- {
199
- if(_1.None) {
200
- result_ = ff_core_Option.Some(ff_core_Option.None())
201
- break
202
- }
203
- }
204
- {
205
- if(_1.Some) {
206
- const o_ = _1.value_;
207
- inner_.close_();
208
- inner_ = body_(o_)
209
- break
210
- }
211
- }
212
- } while(false)
213
- break
214
- }
215
- }
216
- } while(false)
217
- };
218
- return ff_core_Option.Option_grab(result_)
219
- }), (() => {
220
- try {
221
- inner_.close_()
222
- } finally {
223
- self_.close_()
224
- }
225
- }))
226
- }
227
-
228
- export function Stream_collect(self_, body_) {
229
- return ff_core_Stream.Stream_flatMap(self_, ((_w1) => {
230
- return ff_core_Option.Option_toStream(body_(_w1), false)
231
- }))
232
- }
233
-
234
- export function Stream_filter(self_, body_) {
235
- return ff_core_Stream.Stream((() => {
236
- let result_ = ff_core_Option.None();
237
- while(ff_core_Option.Option_isEmpty(result_)) {
238
- do {
239
- const _1 = self_.next_();
240
- {
241
- if(_1.Some) {
242
- const x_ = _1.value_;
243
- const _guard1 = body_(x_);
244
- if(_guard1) {
245
- result_ = ff_core_Option.Some(ff_core_Option.Some(x_))
246
- break
247
- }
248
- }
249
- }
250
- {
251
- if(_1.Some) {
252
-
253
- break
254
- }
255
- }
256
- {
257
- if(_1.None) {
258
- result_ = ff_core_Option.Some(ff_core_Option.None())
259
- break
260
- }
261
- }
262
- } while(false)
263
- };
264
- return ff_core_Option.Option_grab(result_)
265
- }), (() => {
266
- self_.close_()
267
- }))
268
- }
269
-
270
- export function Stream_zip(self_, that_) {
271
- return ff_core_Stream.Stream((() => {
272
- {
273
- const _1 = ff_core_Pair.Pair(self_.next_(), that_.next_());
274
- {
275
- if(_1.first_.Some) {
276
- const x_ = _1.first_.value_;
277
- if(_1.second_.Some) {
278
- const y_ = _1.second_.value_;
279
- return ff_core_Option.Some(ff_core_Pair.Pair(x_, y_))
280
- return
281
- }
282
- }
283
- }
284
- {
285
- return ff_core_Option.None()
286
- return
287
- }
288
- }
289
- }), (() => {
290
- try {
291
- self_.close_()
292
- } finally {
293
- that_.close_()
294
- }
295
- }))
296
- }
297
-
298
- export function Stream_takeFirst(self_, count_ = 1) {
299
- let remaining_ = count_;
300
- return ff_core_Stream.Stream((() => {
301
- return ff_core_Option.Option_filter(self_.next_(), ((_) => {
302
- remaining_ -= 1;
303
- return (remaining_ >= 0)
304
- }))
305
- }), (() => {
306
- self_.close_()
307
- }))
308
- }
309
-
310
- export function Stream_dropFirst(self_, count_ = 1) {
311
- let remaining_ = count_;
312
- return ff_core_Stream.Stream((() => {
313
- while((remaining_ >= 1)) {
314
- do {
315
- const _1 = self_.next_();
316
- {
317
- if(_1.None) {
318
- remaining_ = 0
319
- break
320
- }
321
- }
322
- {
323
- if(_1.Some) {
324
- remaining_ -= 1
325
- break
326
- }
327
- }
328
- } while(false)
329
- };
330
- return self_.next_()
331
- }), (() => {
332
- self_.close_()
333
- }))
334
- }
335
-
336
- export function Stream_takeWhile(self_, body_) {
337
- let done_ = false;
338
- return ff_core_Stream.Stream((() => {
339
- if(done_) {
340
- return ff_core_Option.None()
341
- } else {
342
- {
343
- const _1 = self_.next_();
344
- {
345
- if(_1.None) {
346
- done_ = true;
347
- return ff_core_Option.None()
348
- return
349
- }
350
- }
351
- {
352
- const o_ = _1;
353
- if(_1.Some) {
354
- const x_ = _1.value_;
355
- done_ = (!body_(x_));
356
- if(done_) {
357
- return ff_core_Option.None()
358
- } else {
359
- return o_
360
- }
361
- return
362
- }
363
- }
364
- }
365
- }
366
- }), (() => {
367
- self_.close_()
368
- }))
369
- }
370
-
371
- export function Stream_dropWhile(self_, body_) {
372
- let done_ = false;
373
- return ff_core_Stream.Stream((() => {
374
- if((!done_)) {
375
- let result_ = ff_core_Option.None();
376
- while((!done_)) {
377
- do {
378
- const _1 = self_.next_();
379
- {
380
- if(_1.None) {
381
- done_ = true
382
- break
383
- }
384
- }
385
- {
386
- if(_1.Some) {
387
- const x_ = _1.value_;
388
- const _guard1 = body_(x_);
389
- if(_guard1) {
390
-
391
- break
392
- }
393
- }
394
- }
395
- {
396
- const o_ = _1;
397
- if(_1.Some) {
398
- const x_ = _1.value_;
399
- result_ = o_;
400
- done_ = true
401
- break
402
- }
403
- }
404
- } while(false)
405
- };
406
- return result_
407
- } else {
408
- return self_.next_()
409
- }
410
- }), (() => {
411
- self_.close_()
412
- }))
413
- }
414
-
415
- export function Stream_pairs(self_) {
416
- let i_ = 0;
417
- return ff_core_Stream.Stream_map(self_, ((x_) => {
418
- const r_ = ff_core_Pair.Pair(i_, x_);
419
- i_ += 1;
420
- return r_
421
- }))
422
- }
423
-
424
- export function Stream_chunked(self_, size_) {
425
- let remaining_ = size_;
426
- return ff_core_Stream.Stream((() => {
427
- if((remaining_ <= 0)) {
428
- return ff_core_Option.None()
429
- } else {
430
- {
431
- const _1 = self_.next_();
432
- {
433
- if(_1.None) {
434
- remaining_ = (-1);
435
- return ff_core_Option.None()
436
- return
437
- }
438
- }
439
- {
440
- if(_1.Some) {
441
- const x_ = _1.value_;
442
- let list_ = ff_core_List.Link(x_, ff_core_List.Empty());
443
- remaining_ -= 1;
444
- while((remaining_ > 0)) {
445
- remaining_ -= 1;
446
- do {
447
- const _1 = self_.next_();
448
- {
449
- if(_1.None) {
450
- remaining_ = (-1)
451
- break
452
- }
453
- }
454
- {
455
- if(_1.Some) {
456
- const x_ = _1.value_;
457
- list_ = ff_core_List.Link(x_, list_)
458
- break
459
- }
460
- }
461
- } while(false)
462
- };
463
- if((remaining_ !== (-1))) {
464
- remaining_ = size_
465
- };
466
- return ff_core_Option.Some(ff_core_List.List_reverse(list_))
467
- return
468
- }
469
- }
470
- }
471
- }
472
- }), (() => {
473
- self_.close_()
474
- }))
475
- }
476
-
477
- export function Stream_use(self_, body_) {
478
- try {
479
- return body_(self_)
480
- } finally {
481
- self_.close_()
482
- }
483
- }
484
-
485
- export function Stream_each(self_, body_) {
486
- try {
487
- let done_ = false;
488
- while((!done_)) {
489
- do {
490
- const _1 = self_.next_();
491
- {
492
- if(_1.None) {
493
- done_ = true
494
- break
495
- }
496
- }
497
- {
498
- if(_1.Some) {
499
- const x_ = _1.value_;
500
- body_(x_)
501
- break
502
- }
503
- }
504
- } while(false)
505
- }
506
- } finally {
507
- self_.close_()
508
- }
509
- }
510
-
511
- export function Stream_eachWhile(self_, body_) {
512
- try {
513
- let done_ = false;
514
- while((!done_)) {
515
- do {
516
- const _1 = self_.next_();
517
- {
518
- if(_1.None) {
519
- done_ = true
520
- break
521
- }
522
- }
523
- {
524
- if(_1.Some) {
525
- const x_ = _1.value_;
526
- done_ = (!body_(x_))
527
- break
528
- }
529
- }
530
- } while(false)
531
- }
532
- } finally {
533
- self_.close_()
534
- }
535
- }
536
-
537
- export function Stream_all(self_, body_) {
538
- let result_ = true;
539
- ff_core_Stream.Stream_eachWhile(self_, ((x_) => {
540
- result_ = (result_ && body_(x_));
541
- return result_
542
- }));
543
- return result_
544
- }
545
-
546
- export function Stream_any(self_, body_) {
547
- let result_ = false;
548
- ff_core_Stream.Stream_eachWhile(self_, ((x_) => {
549
- result_ = (result_ || body_(x_));
550
- return (!result_)
551
- }));
552
- return result_
553
- }
554
-
555
- export function Stream_first(self_) {
556
- try {
557
- return self_.next_()
558
- } finally {
559
- self_.close_()
560
- }
561
- }
562
-
563
- export function Stream_last(self_) {
564
- try {
565
- let done_ = false;
566
- let result_ = ff_core_Option.None();
567
- while((!done_)) {
568
- do {
569
- const _1 = self_.next_();
570
- {
571
- if(_1.None) {
572
- done_ = true
573
- break
574
- }
575
- }
576
- {
577
- const o_ = _1;
578
- if(_1.Some) {
579
- const x_ = _1.value_;
580
- result_ = o_
581
- break
582
- }
583
- }
584
- } while(false)
585
- };
586
- return result_
587
- } finally {
588
- self_.close_()
589
- }
590
- }
591
-
592
- export function Stream_grabFirst(self_) {
593
- return ff_core_Option.Option_else(ff_core_Stream.Stream_first(self_), (() => {
594
- return ff_core_Core.panic_("grabFirst() on empty iterator")
595
- }))
596
- }
597
-
598
- export function Stream_grabLast(self_) {
599
- return ff_core_Option.Option_else(ff_core_Stream.Stream_last(self_), (() => {
600
- return ff_core_Core.panic_("grabLast() on empty iterator")
601
- }))
602
- }
603
-
604
- export function Stream_collectFirst(self_, body_) {
605
- try {
606
- let done_ = false;
607
- let result_ = ff_core_Option.None();
608
- while((!done_)) {
609
- do {
610
- const _1 = self_.next_();
611
- {
612
- if(_1.None) {
613
- done_ = true
614
- break
615
- }
616
- }
617
- {
618
- if(_1.Some) {
619
- const x_ = _1.value_;
620
- do {
621
- const _1 = body_(x_);
622
- {
623
- if(_1.None) {
624
-
625
- break
626
- }
627
- }
628
- {
629
- const o_ = _1;
630
- done_ = true;
631
- result_ = o_
632
- break
633
- }
634
- } while(false)
635
- break
636
- }
637
- }
638
- } while(false)
639
- };
640
- return result_
641
- } finally {
642
- self_.close_()
643
- }
644
- }
645
-
646
- export function Stream_find(self_, body_) {
647
- return ff_core_Stream.Stream_first(ff_core_Stream.Stream_filter(self_, body_))
648
- }
649
-
650
- export function Stream_foldLeft(self_, initial_, body_) {
651
- let result_ = initial_;
652
- ff_core_Stream.Stream_each(self_, ((_w1) => {
653
- result_ = body_(result_, _w1)
654
- }));
655
- return result_
656
- }
657
-
658
- export function Stream_toStack(self_) {
659
- const stack_ = ff_core_Stack.make_();
660
- ff_core_Stream.Stream_each(self_, ((_w1) => {
661
- ff_core_Stack.Stack_push(stack_, _w1)
662
- }));
663
- return stack_
664
- }
665
-
666
- export function Stream_toArray(self_) {
667
- return ff_core_Stack.Stack_drain(ff_core_Stream.Stream_toStack(self_))
668
- }
669
-
670
- export function Stream_toList(self_) {
671
- return ff_core_Stack.Stack_toList(ff_core_Stream.Stream_toStack(self_), 0, 9007199254740991)
672
- }
673
-
674
- export async function Stream_addAll$(self_, that_, $task) {
675
- let firstDone_ = false;
676
- return ff_core_Stream.Stream((async ($task) => {
677
- if(firstDone_) {
678
- return (await that_.next_($task))
679
- } else {
680
- return (await ff_core_Option.Option_orElse$((await self_.next_($task)), (async ($task) => {
681
- firstDone_ = true;
682
- return (await that_.next_($task))
683
- }), $task))
684
- }
685
- }), (async ($task) => {
686
- try {
687
- (await self_.close_($task))
688
- } finally {
689
- (await that_.close_($task))
690
- }
691
- }))
692
- }
693
-
694
- export async function Stream_map$(self_, body_, $task) {
695
- return ff_core_Stream.Stream((async ($task) => {
696
- return (await ff_core_Option.Option_map$((await self_.next_($task)), body_, $task))
697
- }), (async ($task) => {
698
- (await self_.close_($task))
699
- }))
700
- }
701
-
702
- export async function Stream_flatMap$(self_, body_, $task) {
703
- let inner_ = ff_core_Stream.Stream((async ($task) => {
704
- return ff_core_Option.None()
705
- }), (async ($task) => {
706
-
707
- }));
708
- return ff_core_Stream.Stream((async ($task) => {
709
- let result_ = ff_core_Option.None();
710
- while(ff_core_Option.Option_isEmpty(result_)) {
711
- do {
712
- const _1 = (await inner_.next_($task));
713
- {
714
- const i_ = _1;
715
- if(_1.Some) {
716
- result_ = ff_core_Option.Some(i_)
717
- break
718
- }
719
- }
720
- {
721
- if(_1.None) {
722
- do {
723
- const _1 = (await self_.next_($task));
724
- {
725
- if(_1.None) {
726
- result_ = ff_core_Option.Some(ff_core_Option.None())
727
- break
728
- }
729
- }
730
- {
731
- if(_1.Some) {
732
- const o_ = _1.value_;
733
- (await inner_.close_($task));
734
- inner_ = (await body_(o_, $task))
735
- break
736
- }
737
- }
738
- } while(false)
739
- break
740
- }
741
- }
742
- } while(false)
743
- };
744
- return ff_core_Option.Option_grab(result_)
745
- }), (async ($task) => {
746
- try {
747
- (await inner_.close_($task))
748
- } finally {
749
- (await self_.close_($task))
750
- }
751
- }))
752
- }
753
-
754
- export async function Stream_collect$(self_, body_, $task) {
755
- return (await ff_core_Stream.Stream_flatMap$(self_, (async (_w1, $task) => {
756
- return (await ff_core_Option.Option_toStream$((await body_(_w1, $task)), false, $task))
757
- }), $task))
758
- }
759
-
760
- export async function Stream_filter$(self_, body_, $task) {
761
- return ff_core_Stream.Stream((async ($task) => {
762
- let result_ = ff_core_Option.None();
763
- while(ff_core_Option.Option_isEmpty(result_)) {
764
- do {
765
- const _1 = (await self_.next_($task));
766
- {
767
- if(_1.Some) {
768
- const x_ = _1.value_;
769
- const _guard1 = (await body_(x_, $task));
770
- if(_guard1) {
771
- result_ = ff_core_Option.Some(ff_core_Option.Some(x_))
772
- break
773
- }
774
- }
775
- }
776
- {
777
- if(_1.Some) {
778
-
779
- break
780
- }
781
- }
782
- {
783
- if(_1.None) {
784
- result_ = ff_core_Option.Some(ff_core_Option.None())
785
- break
786
- }
787
- }
788
- } while(false)
789
- };
790
- return ff_core_Option.Option_grab(result_)
791
- }), (async ($task) => {
792
- (await self_.close_($task))
793
- }))
794
- }
795
-
796
- export async function Stream_zip$(self_, that_, $task) {
797
- return ff_core_Stream.Stream((async ($task) => {
798
- {
799
- const _1 = ff_core_Pair.Pair((await self_.next_($task)), (await that_.next_($task)));
800
- {
801
- if(_1.first_.Some) {
802
- const x_ = _1.first_.value_;
803
- if(_1.second_.Some) {
804
- const y_ = _1.second_.value_;
805
- return ff_core_Option.Some(ff_core_Pair.Pair(x_, y_))
806
- return
807
- }
808
- }
809
- }
810
- {
811
- return ff_core_Option.None()
812
- return
813
- }
814
- }
815
- }), (async ($task) => {
816
- try {
817
- (await self_.close_($task))
818
- } finally {
819
- (await that_.close_($task))
820
- }
821
- }))
822
- }
823
-
824
- export async function Stream_takeFirst$(self_, count_ = 1, $task) {
825
- let remaining_ = count_;
826
- return ff_core_Stream.Stream((async ($task) => {
827
- return ff_core_Option.Option_filter((await self_.next_($task)), ((_) => {
828
- remaining_ -= 1;
829
- return (remaining_ >= 0)
830
- }))
831
- }), (async ($task) => {
832
- (await self_.close_($task))
833
- }))
834
- }
835
-
836
- export async function Stream_dropFirst$(self_, count_ = 1, $task) {
837
- let remaining_ = count_;
838
- return ff_core_Stream.Stream((async ($task) => {
839
- while((remaining_ >= 1)) {
840
- do {
841
- const _1 = (await self_.next_($task));
842
- {
843
- if(_1.None) {
844
- remaining_ = 0
845
- break
846
- }
847
- }
848
- {
849
- if(_1.Some) {
850
- remaining_ -= 1
851
- break
852
- }
853
- }
854
- } while(false)
855
- };
856
- return (await self_.next_($task))
857
- }), (async ($task) => {
858
- (await self_.close_($task))
859
- }))
860
- }
861
-
862
- export async function Stream_takeWhile$(self_, body_, $task) {
863
- let done_ = false;
864
- return ff_core_Stream.Stream((async ($task) => {
865
- if(done_) {
866
- return ff_core_Option.None()
867
- } else {
868
- {
869
- const _1 = (await self_.next_($task));
870
- {
871
- if(_1.None) {
872
- done_ = true;
873
- return ff_core_Option.None()
874
- return
875
- }
876
- }
877
- {
878
- const o_ = _1;
879
- if(_1.Some) {
880
- const x_ = _1.value_;
881
- done_ = (!(await body_(x_, $task)));
882
- if(done_) {
883
- return ff_core_Option.None()
884
- } else {
885
- return o_
886
- }
887
- return
888
- }
889
- }
890
- }
891
- }
892
- }), (async ($task) => {
893
- (await self_.close_($task))
894
- }))
895
- }
896
-
897
- export async function Stream_dropWhile$(self_, body_, $task) {
898
- let done_ = false;
899
- return ff_core_Stream.Stream((async ($task) => {
900
- if((!done_)) {
901
- let result_ = ff_core_Option.None();
902
- while((!done_)) {
903
- do {
904
- const _1 = (await self_.next_($task));
905
- {
906
- if(_1.None) {
907
- done_ = true
908
- break
909
- }
910
- }
911
- {
912
- if(_1.Some) {
913
- const x_ = _1.value_;
914
- const _guard1 = (await body_(x_, $task));
915
- if(_guard1) {
916
-
917
- break
918
- }
919
- }
920
- }
921
- {
922
- const o_ = _1;
923
- if(_1.Some) {
924
- const x_ = _1.value_;
925
- result_ = o_;
926
- done_ = true
927
- break
928
- }
929
- }
930
- } while(false)
931
- };
932
- return result_
933
- } else {
934
- return (await self_.next_($task))
935
- }
936
- }), (async ($task) => {
937
- (await self_.close_($task))
938
- }))
939
- }
940
-
941
- export async function Stream_pairs$(self_, $task) {
942
- let i_ = 0;
943
- return (await ff_core_Stream.Stream_map$(self_, (async (x_, $task) => {
944
- const r_ = ff_core_Pair.Pair(i_, x_);
945
- i_ += 1;
946
- return r_
947
- }), $task))
948
- }
949
-
950
- export async function Stream_chunked$(self_, size_, $task) {
951
- let remaining_ = size_;
952
- return ff_core_Stream.Stream((async ($task) => {
953
- if((remaining_ <= 0)) {
954
- return ff_core_Option.None()
955
- } else {
956
- {
957
- const _1 = (await self_.next_($task));
958
- {
959
- if(_1.None) {
960
- remaining_ = (-1);
961
- return ff_core_Option.None()
962
- return
963
- }
964
- }
965
- {
966
- if(_1.Some) {
967
- const x_ = _1.value_;
968
- let list_ = ff_core_List.Link(x_, ff_core_List.Empty());
969
- remaining_ -= 1;
970
- while((remaining_ > 0)) {
971
- remaining_ -= 1;
972
- do {
973
- const _1 = (await self_.next_($task));
974
- {
975
- if(_1.None) {
976
- remaining_ = (-1)
977
- break
978
- }
979
- }
980
- {
981
- if(_1.Some) {
982
- const x_ = _1.value_;
983
- list_ = ff_core_List.Link(x_, list_)
984
- break
985
- }
986
- }
987
- } while(false)
988
- };
989
- if((remaining_ !== (-1))) {
990
- remaining_ = size_
991
- };
992
- return ff_core_Option.Some(ff_core_List.List_reverse(list_))
993
- return
994
- }
995
- }
996
- }
997
- }
998
- }), (async ($task) => {
999
- (await self_.close_($task))
1000
- }))
1001
- }
1002
-
1003
- export async function Stream_use$(self_, body_, $task) {
1004
- try {
1005
- return (await body_(self_, $task))
1006
- } finally {
1007
- (await self_.close_($task))
1008
- }
1009
- }
1010
-
1011
- export async function Stream_each$(self_, body_, $task) {
1012
- try {
1013
- let done_ = false;
1014
- while((!done_)) {
1015
- do {
1016
- const _1 = (await self_.next_($task));
1017
- {
1018
- if(_1.None) {
1019
- done_ = true
1020
- break
1021
- }
1022
- }
1023
- {
1024
- if(_1.Some) {
1025
- const x_ = _1.value_;
1026
- (await body_(x_, $task))
1027
- break
1028
- }
1029
- }
1030
- } while(false)
1031
- }
1032
- } finally {
1033
- (await self_.close_($task))
1034
- }
1035
- }
1036
-
1037
- export async function Stream_eachWhile$(self_, body_, $task) {
1038
- try {
1039
- let done_ = false;
1040
- while((!done_)) {
1041
- do {
1042
- const _1 = (await self_.next_($task));
1043
- {
1044
- if(_1.None) {
1045
- done_ = true
1046
- break
1047
- }
1048
- }
1049
- {
1050
- if(_1.Some) {
1051
- const x_ = _1.value_;
1052
- done_ = (!(await body_(x_, $task)))
1053
- break
1054
- }
1055
- }
1056
- } while(false)
1057
- }
1058
- } finally {
1059
- (await self_.close_($task))
1060
- }
1061
- }
1062
-
1063
- export async function Stream_all$(self_, body_, $task) {
1064
- let result_ = true;
1065
- (await ff_core_Stream.Stream_eachWhile$(self_, (async (x_, $task) => {
1066
- result_ = (result_ && (await body_(x_, $task)));
1067
- return result_
1068
- }), $task));
1069
- return result_
1070
- }
1071
-
1072
- export async function Stream_any$(self_, body_, $task) {
1073
- let result_ = false;
1074
- (await ff_core_Stream.Stream_eachWhile$(self_, (async (x_, $task) => {
1075
- result_ = (result_ || (await body_(x_, $task)));
1076
- return (!result_)
1077
- }), $task));
1078
- return result_
1079
- }
1080
-
1081
- export async function Stream_first$(self_, $task) {
1082
- try {
1083
- return (await self_.next_($task))
1084
- } finally {
1085
- (await self_.close_($task))
1086
- }
1087
- }
1088
-
1089
- export async function Stream_last$(self_, $task) {
1090
- try {
1091
- let done_ = false;
1092
- let result_ = ff_core_Option.None();
1093
- while((!done_)) {
1094
- do {
1095
- const _1 = (await self_.next_($task));
1096
- {
1097
- if(_1.None) {
1098
- done_ = true
1099
- break
1100
- }
1101
- }
1102
- {
1103
- const o_ = _1;
1104
- if(_1.Some) {
1105
- const x_ = _1.value_;
1106
- result_ = o_
1107
- break
1108
- }
1109
- }
1110
- } while(false)
1111
- };
1112
- return result_
1113
- } finally {
1114
- (await self_.close_($task))
1115
- }
1116
- }
1117
-
1118
- export async function Stream_grabFirst$(self_, $task) {
1119
- return ff_core_Option.Option_else((await ff_core_Stream.Stream_first$(self_, $task)), (() => {
1120
- return ff_core_Core.panic_("grabFirst() on empty iterator")
1121
- }))
1122
- }
1123
-
1124
- export async function Stream_grabLast$(self_, $task) {
1125
- return ff_core_Option.Option_else((await ff_core_Stream.Stream_last$(self_, $task)), (() => {
1126
- return ff_core_Core.panic_("grabLast() on empty iterator")
1127
- }))
1128
- }
1129
-
1130
- export async function Stream_collectFirst$(self_, body_, $task) {
1131
- try {
1132
- let done_ = false;
1133
- let result_ = ff_core_Option.None();
1134
- while((!done_)) {
1135
- do {
1136
- const _1 = (await self_.next_($task));
1137
- {
1138
- if(_1.None) {
1139
- done_ = true
1140
- break
1141
- }
1142
- }
1143
- {
1144
- if(_1.Some) {
1145
- const x_ = _1.value_;
1146
- do {
1147
- const _1 = (await body_(x_, $task));
1148
- {
1149
- if(_1.None) {
1150
-
1151
- break
1152
- }
1153
- }
1154
- {
1155
- const o_ = _1;
1156
- done_ = true;
1157
- result_ = o_
1158
- break
1159
- }
1160
- } while(false)
1161
- break
1162
- }
1163
- }
1164
- } while(false)
1165
- };
1166
- return result_
1167
- } finally {
1168
- (await self_.close_($task))
1169
- }
1170
- }
1171
-
1172
- export async function Stream_find$(self_, body_, $task) {
1173
- return (await ff_core_Stream.Stream_first$((await ff_core_Stream.Stream_filter$(self_, body_, $task)), $task))
1174
- }
1175
-
1176
- export async function Stream_foldLeft$(self_, initial_, body_, $task) {
1177
- let result_ = initial_;
1178
- (await ff_core_Stream.Stream_each$(self_, (async (_w1, $task) => {
1179
- result_ = (await body_(result_, _w1, $task))
1180
- }), $task));
1181
- return result_
1182
- }
1183
-
1184
- export async function Stream_toStack$(self_, $task) {
1185
- const stack_ = ff_core_Stack.make_();
1186
- (await ff_core_Stream.Stream_each$(self_, (async (_w1, $task) => {
1187
- ff_core_Stack.Stack_push(stack_, _w1)
1188
- }), $task));
1189
- return stack_
1190
- }
1191
-
1192
- export async function Stream_toArray$(self_, $task) {
1193
- return ff_core_Stack.Stack_drain((await ff_core_Stream.Stream_toStack$(self_, $task)))
1194
- }
1195
-
1196
- export async function Stream_toList$(self_, $task) {
1197
- return ff_core_Stack.Stack_toList((await ff_core_Stream.Stream_toStack$(self_, $task)), 0, 9007199254740991)
1198
- }
1199
-
1200
- export function Stream_flatten(self_) {
1201
- return ff_core_Stream.Stream_flatMap(self_, ((_w1) => {
1202
- return _w1
1203
- }))
1204
- }
1205
-
1206
- export async function Stream_flatten$(self_, $task) {
1207
- return (await ff_core_Stream.Stream_flatMap$(self_, (async (_w1, $task) => {
1208
- return _w1
1209
- }), $task))
1210
- }
1211
-
1212
- export function Stream_toSet(self_, ff_core_Ordering_Order$T) {
1213
- return ff_core_Array.Array_toSet(ff_core_Stream.Stream_toArray(self_), ff_core_Ordering_Order$T)
1214
- }
1215
-
1216
- export async function Stream_toSet$(self_, ff_core_Ordering_Order$T, $task) {
1217
- return ff_core_Array.Array_toSet((await ff_core_Stream.Stream_toArray$(self_, $task)), ff_core_Ordering_Order$T)
1218
- }
1219
-
1220
- export function Stream_toMap(self_, ff_core_Ordering_Order$K) {
1221
- return ff_core_Array.Array_toMap(ff_core_Stream.Stream_toArray(self_), ff_core_Ordering_Order$K)
1222
- }
1223
-
1224
- export async function Stream_toMap$(self_, ff_core_Ordering_Order$K, $task) {
1225
- return ff_core_Array.Array_toMap((await ff_core_Stream.Stream_toArray$(self_, $task)), ff_core_Ordering_Order$K)
1226
- }
1227
-
1228
- export function Stream_toBuffer(self_) {
1229
- const builder_ = ff_core_Stack.make_();
1230
- ff_core_Stream.Stream_each(self_, ((_w1) => {
1231
- ff_core_Stack.Stack_push(builder_, _w1)
1232
- }));
1233
- return ff_core_Buffer.fromBufferArray_(ff_core_Stack.Stack_drain(builder_))
1234
- }
1235
-
1236
- export function Stream_toString(self_, encoding_ = "utf8") {
1237
- return ff_core_Buffer.Buffer_toString(ff_core_Stream.Stream_toBuffer(self_), encoding_)
1238
- }
1239
-
1240
- export function Stream_readBytes(self_, bytes_) {
1241
- if((bytes_ <= 0)) {
1242
- return ff_core_Pair.Pair(ff_core_List.List_toArray(ff_core_List.Empty()), self_)
1243
- } else {
1244
- const buffers_ = ff_core_Stack.make_();
1245
- let buffer_ = ff_core_Option.Option_grab(self_.next_());
1246
- let taken_ = 0;
1247
- let remainder_ = ff_core_Option.None();
1248
- while(ff_core_Option.ff_core_Equal_Equal$ff_core_Option_Option(ff_core_Buffer.ff_core_Equal_Equal$ff_core_Buffer_Buffer).equals_(remainder_, ff_core_Option.None())) {
1249
- const needed_ = (bytes_ - taken_);
1250
- if((needed_ > ff_core_Buffer.Buffer_size(buffer_))) {
1251
- ff_core_Stack.Stack_push(buffers_, buffer_);
1252
- taken_ += ff_core_Buffer.Buffer_size(buffer_);
1253
- buffer_ = ff_core_Option.Option_grab(self_.next_())
1254
- } else {
1255
- ff_core_Stack.Stack_push(buffers_, ff_core_Buffer.Buffer_view(buffer_, 0, needed_));
1256
- remainder_ = ff_core_Option.Some(ff_core_Buffer.Buffer_view(buffer_, needed_, ff_core_Buffer.Buffer_size(buffer_)))
1257
- }
1258
- };
1259
- return ff_core_Pair.Pair(ff_core_Stack.Stack_drain(buffers_), ff_core_Stream.Stream_addAll(ff_core_Option.Option_toStream(remainder_, false), self_))
1260
- }
1261
- }
1262
-
1263
- export async function Stream_toBuffer$(self_, $task) {
1264
- const builder_ = ff_core_Stack.make_();
1265
- (await ff_core_Stream.Stream_each$(self_, (async (_w1, $task) => {
1266
- ff_core_Stack.Stack_push(builder_, _w1)
1267
- }), $task));
1268
- return ff_core_Buffer.fromBufferArray_(ff_core_Stack.Stack_drain(builder_))
1269
- }
1270
-
1271
- export async function Stream_toString$(self_, encoding_ = "utf8", $task) {
1272
- return ff_core_Buffer.Buffer_toString((await ff_core_Stream.Stream_toBuffer$(self_, $task)), encoding_)
1273
- }
1274
-
1275
- export async function Stream_readBytes$(self_, bytes_, $task) {
1276
- if((bytes_ <= 0)) {
1277
- return ff_core_Pair.Pair(ff_core_List.List_toArray(ff_core_List.Empty()), self_)
1278
- } else {
1279
- const buffers_ = ff_core_Stack.make_();
1280
- let buffer_ = ff_core_Option.Option_grab((await self_.next_($task)));
1281
- let taken_ = 0;
1282
- let remainder_ = ff_core_Option.None();
1283
- while(ff_core_Option.ff_core_Equal_Equal$ff_core_Option_Option(ff_core_Buffer.ff_core_Equal_Equal$ff_core_Buffer_Buffer).equals_(remainder_, ff_core_Option.None())) {
1284
- const needed_ = (bytes_ - taken_);
1285
- if((needed_ > ff_core_Buffer.Buffer_size(buffer_))) {
1286
- ff_core_Stack.Stack_push(buffers_, buffer_);
1287
- taken_ += ff_core_Buffer.Buffer_size(buffer_);
1288
- buffer_ = ff_core_Option.Option_grab((await self_.next_($task)))
1289
- } else {
1290
- ff_core_Stack.Stack_push(buffers_, ff_core_Buffer.Buffer_view(buffer_, 0, needed_));
1291
- remainder_ = ff_core_Option.Some(ff_core_Buffer.Buffer_view(buffer_, needed_, ff_core_Buffer.Buffer_size(buffer_)))
1292
- }
1293
- };
1294
- return ff_core_Pair.Pair(ff_core_Stack.Stack_drain(buffers_), (await ff_core_Stream.Stream_addAll$((await ff_core_Option.Option_toStream$(remainder_, false, $task)), self_, $task)))
1295
- }
1296
- }
1297
-
1298
-
1299
-
1300
-
1
+
2
+
3
+ import * as ff_core_Any from "../../ff/core/Any.mjs"
4
+
5
+ import * as ff_core_Array from "../../ff/core/Array.mjs"
6
+
7
+ import * as ff_core_AssetSystem from "../../ff/core/AssetSystem.mjs"
8
+
9
+ import * as ff_core_Atomic from "../../ff/core/Atomic.mjs"
10
+
11
+ import * as ff_core_Bool from "../../ff/core/Bool.mjs"
12
+
13
+ import * as ff_core_Box from "../../ff/core/Box.mjs"
14
+
15
+ import * as ff_core_BrowserSystem from "../../ff/core/BrowserSystem.mjs"
16
+
17
+ import * as ff_core_Buffer from "../../ff/core/Buffer.mjs"
18
+
19
+ import * as ff_core_BuildSystem from "../../ff/core/BuildSystem.mjs"
20
+
21
+ import * as ff_core_Channel from "../../ff/core/Channel.mjs"
22
+
23
+ import * as ff_core_Char from "../../ff/core/Char.mjs"
24
+
25
+ import * as ff_core_Core from "../../ff/core/Core.mjs"
26
+
27
+ import * as ff_core_Duration from "../../ff/core/Duration.mjs"
28
+
29
+ import * as ff_core_Equal from "../../ff/core/Equal.mjs"
30
+
31
+ import * as ff_core_Error from "../../ff/core/Error.mjs"
32
+
33
+ import * as ff_core_FileHandle from "../../ff/core/FileHandle.mjs"
34
+
35
+ import * as ff_core_Float from "../../ff/core/Float.mjs"
36
+
37
+ import * as ff_core_HttpClient from "../../ff/core/HttpClient.mjs"
38
+
39
+ import * as ff_core_Instant from "../../ff/core/Instant.mjs"
40
+
41
+ import * as ff_core_Int from "../../ff/core/Int.mjs"
42
+
43
+ import * as ff_core_IntMap from "../../ff/core/IntMap.mjs"
44
+
45
+ import * as ff_core_JsSystem from "../../ff/core/JsSystem.mjs"
46
+
47
+ import * as ff_core_JsValue from "../../ff/core/JsValue.mjs"
48
+
49
+ import * as ff_core_List from "../../ff/core/List.mjs"
50
+
51
+ import * as ff_core_Lock from "../../ff/core/Lock.mjs"
52
+
53
+ import * as ff_core_Log from "../../ff/core/Log.mjs"
54
+
55
+ import * as ff_core_Map from "../../ff/core/Map.mjs"
56
+
57
+ import * as ff_core_NodeSystem from "../../ff/core/NodeSystem.mjs"
58
+
59
+ import * as ff_core_Nothing from "../../ff/core/Nothing.mjs"
60
+
61
+ import * as ff_core_Option from "../../ff/core/Option.mjs"
62
+
63
+ import * as ff_core_Ordering from "../../ff/core/Ordering.mjs"
64
+
65
+ import * as ff_core_Pair from "../../ff/core/Pair.mjs"
66
+
67
+ import * as ff_core_Path from "../../ff/core/Path.mjs"
68
+
69
+ import * as ff_core_Serializable from "../../ff/core/Serializable.mjs"
70
+
71
+ import * as ff_core_Set from "../../ff/core/Set.mjs"
72
+
73
+ import * as ff_core_Show from "../../ff/core/Show.mjs"
74
+
75
+ import * as ff_core_SourceLocation from "../../ff/core/SourceLocation.mjs"
76
+
77
+ import * as ff_core_Stack from "../../ff/core/Stack.mjs"
78
+
79
+ import * as ff_core_Stream from "../../ff/core/Stream.mjs"
80
+
81
+ import * as ff_core_String from "../../ff/core/String.mjs"
82
+
83
+ import * as ff_core_StringMap from "../../ff/core/StringMap.mjs"
84
+
85
+ import * as ff_core_Task from "../../ff/core/Task.mjs"
86
+
87
+ import * as ff_core_Try from "../../ff/core/Try.mjs"
88
+
89
+ import * as ff_core_Unit from "../../ff/core/Unit.mjs"
90
+
91
+ // type Stream
92
+ export function Stream(next_, close_) {
93
+ return {next_, close_};
94
+ }
95
+
96
+
97
+
98
+ export function make_(next_, close_ = (() => {
99
+
100
+ })) {
101
+ return ff_core_Stream.Stream(next_, close_)
102
+ }
103
+
104
+ export function init_(body_) {
105
+ let initialized_ = false;
106
+ let stream_ = ff_core_Stream.Stream((() => {
107
+ return ff_core_Option.None()
108
+ }), (() => {
109
+
110
+ }));
111
+ return ff_core_Stream.Stream((() => {
112
+ if(initialized_) {
113
+ return stream_.next_()
114
+ } else {
115
+ initialized_ = true;
116
+ stream_ = body_();
117
+ return stream_.next_()
118
+ }
119
+ }), (() => {
120
+ initialized_ = true;
121
+ stream_.close_()
122
+ }))
123
+ }
124
+
125
+ export async function make_$(next_, close_ = (async ($task) => {
126
+
127
+ }), $task) {
128
+ return ff_core_Stream.Stream(next_, close_)
129
+ }
130
+
131
+ export async function init_$(body_, $task) {
132
+ let initialized_ = false;
133
+ let stream_ = ff_core_Stream.Stream((async ($task) => {
134
+ return ff_core_Option.None()
135
+ }), (async ($task) => {
136
+
137
+ }));
138
+ return ff_core_Stream.Stream((async ($task) => {
139
+ if(initialized_) {
140
+ return (await stream_.next_($task))
141
+ } else {
142
+ initialized_ = true;
143
+ stream_ = (await body_($task));
144
+ return (await stream_.next_($task))
145
+ }
146
+ }), (async ($task) => {
147
+ initialized_ = true;
148
+ (await stream_.close_($task))
149
+ }))
150
+ }
151
+
152
+ export function Stream_addAll(self_, that_) {
153
+ let firstDone_ = false;
154
+ return ff_core_Stream.Stream((() => {
155
+ if(firstDone_) {
156
+ return that_.next_()
157
+ } else {
158
+ return ff_core_Option.Option_orElse(self_.next_(), (() => {
159
+ firstDone_ = true;
160
+ return that_.next_()
161
+ }))
162
+ }
163
+ }), (() => {
164
+ try {
165
+ self_.close_()
166
+ } finally {
167
+ that_.close_()
168
+ }
169
+ }))
170
+ }
171
+
172
+ export function Stream_map(self_, body_) {
173
+ return ff_core_Stream.Stream((() => {
174
+ return ff_core_Option.Option_map(self_.next_(), body_)
175
+ }), (() => {
176
+ self_.close_()
177
+ }))
178
+ }
179
+
180
+ export function Stream_flatMap(self_, body_) {
181
+ let inner_ = ff_core_Stream.Stream((() => {
182
+ return ff_core_Option.None()
183
+ }), (() => {
184
+
185
+ }));
186
+ return ff_core_Stream.Stream((() => {
187
+ let result_ = ff_core_Option.None();
188
+ while(ff_core_Option.Option_isEmpty(result_)) {
189
+ do {
190
+ const _1 = inner_.next_();
191
+ {
192
+ const i_ = _1;
193
+ if(_1.Some) {
194
+ result_ = ff_core_Option.Some(i_)
195
+ break
196
+ }
197
+ }
198
+ {
199
+ if(_1.None) {
200
+ do {
201
+ const _1 = self_.next_();
202
+ {
203
+ if(_1.None) {
204
+ result_ = ff_core_Option.Some(ff_core_Option.None())
205
+ break
206
+ }
207
+ }
208
+ {
209
+ if(_1.Some) {
210
+ const o_ = _1.value_;
211
+ inner_.close_();
212
+ inner_ = body_(o_)
213
+ break
214
+ }
215
+ }
216
+ } while(false)
217
+ break
218
+ }
219
+ }
220
+ } while(false)
221
+ };
222
+ return ff_core_Option.Option_grab(result_)
223
+ }), (() => {
224
+ try {
225
+ inner_.close_()
226
+ } finally {
227
+ self_.close_()
228
+ }
229
+ }))
230
+ }
231
+
232
+ export function Stream_collect(self_, body_) {
233
+ return ff_core_Stream.Stream_flatMap(self_, ((_w1) => {
234
+ return ff_core_Option.Option_toStream(body_(_w1), false)
235
+ }))
236
+ }
237
+
238
+ export function Stream_filter(self_, body_) {
239
+ return ff_core_Stream.Stream((() => {
240
+ let result_ = ff_core_Option.None();
241
+ while(ff_core_Option.Option_isEmpty(result_)) {
242
+ do {
243
+ const _1 = self_.next_();
244
+ {
245
+ if(_1.Some) {
246
+ const x_ = _1.value_;
247
+ const _guard1 = body_(x_);
248
+ if(_guard1) {
249
+ result_ = ff_core_Option.Some(ff_core_Option.Some(x_))
250
+ break
251
+ }
252
+ }
253
+ }
254
+ {
255
+ if(_1.Some) {
256
+
257
+ break
258
+ }
259
+ }
260
+ {
261
+ if(_1.None) {
262
+ result_ = ff_core_Option.Some(ff_core_Option.None())
263
+ break
264
+ }
265
+ }
266
+ } while(false)
267
+ };
268
+ return ff_core_Option.Option_grab(result_)
269
+ }), (() => {
270
+ self_.close_()
271
+ }))
272
+ }
273
+
274
+ export function Stream_zip(self_, that_) {
275
+ return ff_core_Stream.Stream((() => {
276
+ {
277
+ const _1 = ff_core_Pair.Pair(self_.next_(), that_.next_());
278
+ {
279
+ if(_1.first_.Some) {
280
+ const x_ = _1.first_.value_;
281
+ if(_1.second_.Some) {
282
+ const y_ = _1.second_.value_;
283
+ return ff_core_Option.Some(ff_core_Pair.Pair(x_, y_))
284
+ return
285
+ }
286
+ }
287
+ }
288
+ {
289
+ return ff_core_Option.None()
290
+ return
291
+ }
292
+ }
293
+ }), (() => {
294
+ try {
295
+ self_.close_()
296
+ } finally {
297
+ that_.close_()
298
+ }
299
+ }))
300
+ }
301
+
302
+ export function Stream_takeFirst(self_, count_ = 1) {
303
+ let remaining_ = count_;
304
+ return ff_core_Stream.Stream((() => {
305
+ return ff_core_Option.Option_filter(self_.next_(), ((_) => {
306
+ remaining_ -= 1;
307
+ return (remaining_ >= 0)
308
+ }))
309
+ }), (() => {
310
+ self_.close_()
311
+ }))
312
+ }
313
+
314
+ export function Stream_dropFirst(self_, count_ = 1) {
315
+ let remaining_ = count_;
316
+ return ff_core_Stream.Stream((() => {
317
+ while((remaining_ >= 1)) {
318
+ do {
319
+ const _1 = self_.next_();
320
+ {
321
+ if(_1.None) {
322
+ remaining_ = 0
323
+ break
324
+ }
325
+ }
326
+ {
327
+ if(_1.Some) {
328
+ remaining_ -= 1
329
+ break
330
+ }
331
+ }
332
+ } while(false)
333
+ };
334
+ return self_.next_()
335
+ }), (() => {
336
+ self_.close_()
337
+ }))
338
+ }
339
+
340
+ export function Stream_takeWhile(self_, body_) {
341
+ let done_ = false;
342
+ return ff_core_Stream.Stream((() => {
343
+ if(done_) {
344
+ return ff_core_Option.None()
345
+ } else {
346
+ {
347
+ const _1 = self_.next_();
348
+ {
349
+ if(_1.None) {
350
+ done_ = true;
351
+ return ff_core_Option.None()
352
+ return
353
+ }
354
+ }
355
+ {
356
+ const o_ = _1;
357
+ if(_1.Some) {
358
+ const x_ = _1.value_;
359
+ done_ = (!body_(x_));
360
+ if(done_) {
361
+ return ff_core_Option.None()
362
+ } else {
363
+ return o_
364
+ }
365
+ return
366
+ }
367
+ }
368
+ }
369
+ }
370
+ }), (() => {
371
+ self_.close_()
372
+ }))
373
+ }
374
+
375
+ export function Stream_dropWhile(self_, body_) {
376
+ let done_ = false;
377
+ return ff_core_Stream.Stream((() => {
378
+ if((!done_)) {
379
+ let result_ = ff_core_Option.None();
380
+ while((!done_)) {
381
+ do {
382
+ const _1 = self_.next_();
383
+ {
384
+ if(_1.None) {
385
+ done_ = true
386
+ break
387
+ }
388
+ }
389
+ {
390
+ if(_1.Some) {
391
+ const x_ = _1.value_;
392
+ const _guard1 = body_(x_);
393
+ if(_guard1) {
394
+
395
+ break
396
+ }
397
+ }
398
+ }
399
+ {
400
+ const o_ = _1;
401
+ if(_1.Some) {
402
+ const x_ = _1.value_;
403
+ result_ = o_;
404
+ done_ = true
405
+ break
406
+ }
407
+ }
408
+ } while(false)
409
+ };
410
+ return result_
411
+ } else {
412
+ return self_.next_()
413
+ }
414
+ }), (() => {
415
+ self_.close_()
416
+ }))
417
+ }
418
+
419
+ export function Stream_pairs(self_) {
420
+ let i_ = 0;
421
+ return ff_core_Stream.Stream_map(self_, ((x_) => {
422
+ const r_ = ff_core_Pair.Pair(i_, x_);
423
+ i_ += 1;
424
+ return r_
425
+ }))
426
+ }
427
+
428
+ export function Stream_chunked(self_, size_) {
429
+ let remaining_ = size_;
430
+ return ff_core_Stream.Stream((() => {
431
+ if((remaining_ <= 0)) {
432
+ return ff_core_Option.None()
433
+ } else {
434
+ {
435
+ const _1 = self_.next_();
436
+ {
437
+ if(_1.None) {
438
+ remaining_ = (-1);
439
+ return ff_core_Option.None()
440
+ return
441
+ }
442
+ }
443
+ {
444
+ if(_1.Some) {
445
+ const x_ = _1.value_;
446
+ let list_ = ff_core_List.Link(x_, ff_core_List.Empty());
447
+ remaining_ -= 1;
448
+ while((remaining_ > 0)) {
449
+ remaining_ -= 1;
450
+ do {
451
+ const _1 = self_.next_();
452
+ {
453
+ if(_1.None) {
454
+ remaining_ = (-1)
455
+ break
456
+ }
457
+ }
458
+ {
459
+ if(_1.Some) {
460
+ const x_ = _1.value_;
461
+ list_ = ff_core_List.Link(x_, list_)
462
+ break
463
+ }
464
+ }
465
+ } while(false)
466
+ };
467
+ if((remaining_ !== (-1))) {
468
+ remaining_ = size_
469
+ };
470
+ return ff_core_Option.Some(ff_core_List.List_reverse(list_))
471
+ return
472
+ }
473
+ }
474
+ }
475
+ }
476
+ }), (() => {
477
+ self_.close_()
478
+ }))
479
+ }
480
+
481
+ export function Stream_use(self_, body_) {
482
+ try {
483
+ return body_(self_)
484
+ } finally {
485
+ self_.close_()
486
+ }
487
+ }
488
+
489
+ export function Stream_each(self_, body_) {
490
+ try {
491
+ let done_ = false;
492
+ while((!done_)) {
493
+ do {
494
+ const _1 = self_.next_();
495
+ {
496
+ if(_1.None) {
497
+ done_ = true
498
+ break
499
+ }
500
+ }
501
+ {
502
+ if(_1.Some) {
503
+ const x_ = _1.value_;
504
+ body_(x_)
505
+ break
506
+ }
507
+ }
508
+ } while(false)
509
+ }
510
+ } finally {
511
+ self_.close_()
512
+ }
513
+ }
514
+
515
+ export function Stream_eachWhile(self_, body_) {
516
+ try {
517
+ let done_ = false;
518
+ while((!done_)) {
519
+ do {
520
+ const _1 = self_.next_();
521
+ {
522
+ if(_1.None) {
523
+ done_ = true
524
+ break
525
+ }
526
+ }
527
+ {
528
+ if(_1.Some) {
529
+ const x_ = _1.value_;
530
+ done_ = (!body_(x_))
531
+ break
532
+ }
533
+ }
534
+ } while(false)
535
+ }
536
+ } finally {
537
+ self_.close_()
538
+ }
539
+ }
540
+
541
+ export function Stream_all(self_, body_) {
542
+ let result_ = true;
543
+ ff_core_Stream.Stream_eachWhile(self_, ((x_) => {
544
+ result_ = (result_ && body_(x_));
545
+ return result_
546
+ }));
547
+ return result_
548
+ }
549
+
550
+ export function Stream_any(self_, body_) {
551
+ let result_ = false;
552
+ ff_core_Stream.Stream_eachWhile(self_, ((x_) => {
553
+ result_ = (result_ || body_(x_));
554
+ return (!result_)
555
+ }));
556
+ return result_
557
+ }
558
+
559
+ export function Stream_first(self_) {
560
+ try {
561
+ return self_.next_()
562
+ } finally {
563
+ self_.close_()
564
+ }
565
+ }
566
+
567
+ export function Stream_last(self_) {
568
+ try {
569
+ let done_ = false;
570
+ let result_ = ff_core_Option.None();
571
+ while((!done_)) {
572
+ do {
573
+ const _1 = self_.next_();
574
+ {
575
+ if(_1.None) {
576
+ done_ = true
577
+ break
578
+ }
579
+ }
580
+ {
581
+ const o_ = _1;
582
+ if(_1.Some) {
583
+ const x_ = _1.value_;
584
+ result_ = o_
585
+ break
586
+ }
587
+ }
588
+ } while(false)
589
+ };
590
+ return result_
591
+ } finally {
592
+ self_.close_()
593
+ }
594
+ }
595
+
596
+ export function Stream_grabFirst(self_) {
597
+ return ff_core_Option.Option_else(ff_core_Stream.Stream_first(self_), (() => {
598
+ return ff_core_Core.panic_("grabFirst() on empty iterator")
599
+ }))
600
+ }
601
+
602
+ export function Stream_grabLast(self_) {
603
+ return ff_core_Option.Option_else(ff_core_Stream.Stream_last(self_), (() => {
604
+ return ff_core_Core.panic_("grabLast() on empty iterator")
605
+ }))
606
+ }
607
+
608
+ export function Stream_collectFirst(self_, body_) {
609
+ try {
610
+ let done_ = false;
611
+ let result_ = ff_core_Option.None();
612
+ while((!done_)) {
613
+ do {
614
+ const _1 = self_.next_();
615
+ {
616
+ if(_1.None) {
617
+ done_ = true
618
+ break
619
+ }
620
+ }
621
+ {
622
+ if(_1.Some) {
623
+ const x_ = _1.value_;
624
+ do {
625
+ const _1 = body_(x_);
626
+ {
627
+ if(_1.None) {
628
+
629
+ break
630
+ }
631
+ }
632
+ {
633
+ const o_ = _1;
634
+ done_ = true;
635
+ result_ = o_
636
+ break
637
+ }
638
+ } while(false)
639
+ break
640
+ }
641
+ }
642
+ } while(false)
643
+ };
644
+ return result_
645
+ } finally {
646
+ self_.close_()
647
+ }
648
+ }
649
+
650
+ export function Stream_find(self_, body_) {
651
+ return ff_core_Stream.Stream_first(ff_core_Stream.Stream_filter(self_, body_))
652
+ }
653
+
654
+ export function Stream_foldLeft(self_, initial_, body_) {
655
+ let result_ = initial_;
656
+ ff_core_Stream.Stream_each(self_, ((_w1) => {
657
+ result_ = body_(result_, _w1)
658
+ }));
659
+ return result_
660
+ }
661
+
662
+ export function Stream_toStack(self_) {
663
+ const stack_ = ff_core_Stack.make_();
664
+ ff_core_Stream.Stream_each(self_, ((_w1) => {
665
+ ff_core_Stack.Stack_push(stack_, _w1)
666
+ }));
667
+ return stack_
668
+ }
669
+
670
+ export function Stream_toArray(self_) {
671
+ return ff_core_Stack.Stack_drain(ff_core_Stream.Stream_toStack(self_))
672
+ }
673
+
674
+ export function Stream_toList(self_) {
675
+ return ff_core_Stack.Stack_toList(ff_core_Stream.Stream_toStack(self_), 0, 9007199254740991)
676
+ }
677
+
678
+ export async function Stream_addAll$(self_, that_, $task) {
679
+ let firstDone_ = false;
680
+ return ff_core_Stream.Stream((async ($task) => {
681
+ if(firstDone_) {
682
+ return (await that_.next_($task))
683
+ } else {
684
+ return (await ff_core_Option.Option_orElse$((await self_.next_($task)), (async ($task) => {
685
+ firstDone_ = true;
686
+ return (await that_.next_($task))
687
+ }), $task))
688
+ }
689
+ }), (async ($task) => {
690
+ try {
691
+ (await self_.close_($task))
692
+ } finally {
693
+ (await that_.close_($task))
694
+ }
695
+ }))
696
+ }
697
+
698
+ export async function Stream_map$(self_, body_, $task) {
699
+ return ff_core_Stream.Stream((async ($task) => {
700
+ return (await ff_core_Option.Option_map$((await self_.next_($task)), body_, $task))
701
+ }), (async ($task) => {
702
+ (await self_.close_($task))
703
+ }))
704
+ }
705
+
706
+ export async function Stream_flatMap$(self_, body_, $task) {
707
+ let inner_ = ff_core_Stream.Stream((async ($task) => {
708
+ return ff_core_Option.None()
709
+ }), (async ($task) => {
710
+
711
+ }));
712
+ return ff_core_Stream.Stream((async ($task) => {
713
+ let result_ = ff_core_Option.None();
714
+ while(ff_core_Option.Option_isEmpty(result_)) {
715
+ do {
716
+ const _1 = (await inner_.next_($task));
717
+ {
718
+ const i_ = _1;
719
+ if(_1.Some) {
720
+ result_ = ff_core_Option.Some(i_)
721
+ break
722
+ }
723
+ }
724
+ {
725
+ if(_1.None) {
726
+ do {
727
+ const _1 = (await self_.next_($task));
728
+ {
729
+ if(_1.None) {
730
+ result_ = ff_core_Option.Some(ff_core_Option.None())
731
+ break
732
+ }
733
+ }
734
+ {
735
+ if(_1.Some) {
736
+ const o_ = _1.value_;
737
+ (await inner_.close_($task));
738
+ inner_ = (await body_(o_, $task))
739
+ break
740
+ }
741
+ }
742
+ } while(false)
743
+ break
744
+ }
745
+ }
746
+ } while(false)
747
+ };
748
+ return ff_core_Option.Option_grab(result_)
749
+ }), (async ($task) => {
750
+ try {
751
+ (await inner_.close_($task))
752
+ } finally {
753
+ (await self_.close_($task))
754
+ }
755
+ }))
756
+ }
757
+
758
+ export async function Stream_collect$(self_, body_, $task) {
759
+ return (await ff_core_Stream.Stream_flatMap$(self_, (async (_w1, $task) => {
760
+ return (await ff_core_Option.Option_toStream$((await body_(_w1, $task)), false, $task))
761
+ }), $task))
762
+ }
763
+
764
+ export async function Stream_filter$(self_, body_, $task) {
765
+ return ff_core_Stream.Stream((async ($task) => {
766
+ let result_ = ff_core_Option.None();
767
+ while(ff_core_Option.Option_isEmpty(result_)) {
768
+ do {
769
+ const _1 = (await self_.next_($task));
770
+ {
771
+ if(_1.Some) {
772
+ const x_ = _1.value_;
773
+ const _guard1 = (await body_(x_, $task));
774
+ if(_guard1) {
775
+ result_ = ff_core_Option.Some(ff_core_Option.Some(x_))
776
+ break
777
+ }
778
+ }
779
+ }
780
+ {
781
+ if(_1.Some) {
782
+
783
+ break
784
+ }
785
+ }
786
+ {
787
+ if(_1.None) {
788
+ result_ = ff_core_Option.Some(ff_core_Option.None())
789
+ break
790
+ }
791
+ }
792
+ } while(false)
793
+ };
794
+ return ff_core_Option.Option_grab(result_)
795
+ }), (async ($task) => {
796
+ (await self_.close_($task))
797
+ }))
798
+ }
799
+
800
+ export async function Stream_zip$(self_, that_, $task) {
801
+ return ff_core_Stream.Stream((async ($task) => {
802
+ {
803
+ const _1 = ff_core_Pair.Pair((await self_.next_($task)), (await that_.next_($task)));
804
+ {
805
+ if(_1.first_.Some) {
806
+ const x_ = _1.first_.value_;
807
+ if(_1.second_.Some) {
808
+ const y_ = _1.second_.value_;
809
+ return ff_core_Option.Some(ff_core_Pair.Pair(x_, y_))
810
+ return
811
+ }
812
+ }
813
+ }
814
+ {
815
+ return ff_core_Option.None()
816
+ return
817
+ }
818
+ }
819
+ }), (async ($task) => {
820
+ try {
821
+ (await self_.close_($task))
822
+ } finally {
823
+ (await that_.close_($task))
824
+ }
825
+ }))
826
+ }
827
+
828
+ export async function Stream_takeFirst$(self_, count_ = 1, $task) {
829
+ let remaining_ = count_;
830
+ return ff_core_Stream.Stream((async ($task) => {
831
+ return ff_core_Option.Option_filter((await self_.next_($task)), ((_) => {
832
+ remaining_ -= 1;
833
+ return (remaining_ >= 0)
834
+ }))
835
+ }), (async ($task) => {
836
+ (await self_.close_($task))
837
+ }))
838
+ }
839
+
840
+ export async function Stream_dropFirst$(self_, count_ = 1, $task) {
841
+ let remaining_ = count_;
842
+ return ff_core_Stream.Stream((async ($task) => {
843
+ while((remaining_ >= 1)) {
844
+ do {
845
+ const _1 = (await self_.next_($task));
846
+ {
847
+ if(_1.None) {
848
+ remaining_ = 0
849
+ break
850
+ }
851
+ }
852
+ {
853
+ if(_1.Some) {
854
+ remaining_ -= 1
855
+ break
856
+ }
857
+ }
858
+ } while(false)
859
+ };
860
+ return (await self_.next_($task))
861
+ }), (async ($task) => {
862
+ (await self_.close_($task))
863
+ }))
864
+ }
865
+
866
+ export async function Stream_takeWhile$(self_, body_, $task) {
867
+ let done_ = false;
868
+ return ff_core_Stream.Stream((async ($task) => {
869
+ if(done_) {
870
+ return ff_core_Option.None()
871
+ } else {
872
+ {
873
+ const _1 = (await self_.next_($task));
874
+ {
875
+ if(_1.None) {
876
+ done_ = true;
877
+ return ff_core_Option.None()
878
+ return
879
+ }
880
+ }
881
+ {
882
+ const o_ = _1;
883
+ if(_1.Some) {
884
+ const x_ = _1.value_;
885
+ done_ = (!(await body_(x_, $task)));
886
+ if(done_) {
887
+ return ff_core_Option.None()
888
+ } else {
889
+ return o_
890
+ }
891
+ return
892
+ }
893
+ }
894
+ }
895
+ }
896
+ }), (async ($task) => {
897
+ (await self_.close_($task))
898
+ }))
899
+ }
900
+
901
+ export async function Stream_dropWhile$(self_, body_, $task) {
902
+ let done_ = false;
903
+ return ff_core_Stream.Stream((async ($task) => {
904
+ if((!done_)) {
905
+ let result_ = ff_core_Option.None();
906
+ while((!done_)) {
907
+ do {
908
+ const _1 = (await self_.next_($task));
909
+ {
910
+ if(_1.None) {
911
+ done_ = true
912
+ break
913
+ }
914
+ }
915
+ {
916
+ if(_1.Some) {
917
+ const x_ = _1.value_;
918
+ const _guard1 = (await body_(x_, $task));
919
+ if(_guard1) {
920
+
921
+ break
922
+ }
923
+ }
924
+ }
925
+ {
926
+ const o_ = _1;
927
+ if(_1.Some) {
928
+ const x_ = _1.value_;
929
+ result_ = o_;
930
+ done_ = true
931
+ break
932
+ }
933
+ }
934
+ } while(false)
935
+ };
936
+ return result_
937
+ } else {
938
+ return (await self_.next_($task))
939
+ }
940
+ }), (async ($task) => {
941
+ (await self_.close_($task))
942
+ }))
943
+ }
944
+
945
+ export async function Stream_pairs$(self_, $task) {
946
+ let i_ = 0;
947
+ return (await ff_core_Stream.Stream_map$(self_, (async (x_, $task) => {
948
+ const r_ = ff_core_Pair.Pair(i_, x_);
949
+ i_ += 1;
950
+ return r_
951
+ }), $task))
952
+ }
953
+
954
+ export async function Stream_chunked$(self_, size_, $task) {
955
+ let remaining_ = size_;
956
+ return ff_core_Stream.Stream((async ($task) => {
957
+ if((remaining_ <= 0)) {
958
+ return ff_core_Option.None()
959
+ } else {
960
+ {
961
+ const _1 = (await self_.next_($task));
962
+ {
963
+ if(_1.None) {
964
+ remaining_ = (-1);
965
+ return ff_core_Option.None()
966
+ return
967
+ }
968
+ }
969
+ {
970
+ if(_1.Some) {
971
+ const x_ = _1.value_;
972
+ let list_ = ff_core_List.Link(x_, ff_core_List.Empty());
973
+ remaining_ -= 1;
974
+ while((remaining_ > 0)) {
975
+ remaining_ -= 1;
976
+ do {
977
+ const _1 = (await self_.next_($task));
978
+ {
979
+ if(_1.None) {
980
+ remaining_ = (-1)
981
+ break
982
+ }
983
+ }
984
+ {
985
+ if(_1.Some) {
986
+ const x_ = _1.value_;
987
+ list_ = ff_core_List.Link(x_, list_)
988
+ break
989
+ }
990
+ }
991
+ } while(false)
992
+ };
993
+ if((remaining_ !== (-1))) {
994
+ remaining_ = size_
995
+ };
996
+ return ff_core_Option.Some(ff_core_List.List_reverse(list_))
997
+ return
998
+ }
999
+ }
1000
+ }
1001
+ }
1002
+ }), (async ($task) => {
1003
+ (await self_.close_($task))
1004
+ }))
1005
+ }
1006
+
1007
+ export async function Stream_use$(self_, body_, $task) {
1008
+ try {
1009
+ return (await body_(self_, $task))
1010
+ } finally {
1011
+ (await self_.close_($task))
1012
+ }
1013
+ }
1014
+
1015
+ export async function Stream_each$(self_, body_, $task) {
1016
+ try {
1017
+ let done_ = false;
1018
+ while((!done_)) {
1019
+ do {
1020
+ const _1 = (await self_.next_($task));
1021
+ {
1022
+ if(_1.None) {
1023
+ done_ = true
1024
+ break
1025
+ }
1026
+ }
1027
+ {
1028
+ if(_1.Some) {
1029
+ const x_ = _1.value_;
1030
+ (await body_(x_, $task))
1031
+ break
1032
+ }
1033
+ }
1034
+ } while(false)
1035
+ }
1036
+ } finally {
1037
+ (await self_.close_($task))
1038
+ }
1039
+ }
1040
+
1041
+ export async function Stream_eachWhile$(self_, body_, $task) {
1042
+ try {
1043
+ let done_ = false;
1044
+ while((!done_)) {
1045
+ do {
1046
+ const _1 = (await self_.next_($task));
1047
+ {
1048
+ if(_1.None) {
1049
+ done_ = true
1050
+ break
1051
+ }
1052
+ }
1053
+ {
1054
+ if(_1.Some) {
1055
+ const x_ = _1.value_;
1056
+ done_ = (!(await body_(x_, $task)))
1057
+ break
1058
+ }
1059
+ }
1060
+ } while(false)
1061
+ }
1062
+ } finally {
1063
+ (await self_.close_($task))
1064
+ }
1065
+ }
1066
+
1067
+ export async function Stream_all$(self_, body_, $task) {
1068
+ let result_ = true;
1069
+ (await ff_core_Stream.Stream_eachWhile$(self_, (async (x_, $task) => {
1070
+ result_ = (result_ && (await body_(x_, $task)));
1071
+ return result_
1072
+ }), $task));
1073
+ return result_
1074
+ }
1075
+
1076
+ export async function Stream_any$(self_, body_, $task) {
1077
+ let result_ = false;
1078
+ (await ff_core_Stream.Stream_eachWhile$(self_, (async (x_, $task) => {
1079
+ result_ = (result_ || (await body_(x_, $task)));
1080
+ return (!result_)
1081
+ }), $task));
1082
+ return result_
1083
+ }
1084
+
1085
+ export async function Stream_first$(self_, $task) {
1086
+ try {
1087
+ return (await self_.next_($task))
1088
+ } finally {
1089
+ (await self_.close_($task))
1090
+ }
1091
+ }
1092
+
1093
+ export async function Stream_last$(self_, $task) {
1094
+ try {
1095
+ let done_ = false;
1096
+ let result_ = ff_core_Option.None();
1097
+ while((!done_)) {
1098
+ do {
1099
+ const _1 = (await self_.next_($task));
1100
+ {
1101
+ if(_1.None) {
1102
+ done_ = true
1103
+ break
1104
+ }
1105
+ }
1106
+ {
1107
+ const o_ = _1;
1108
+ if(_1.Some) {
1109
+ const x_ = _1.value_;
1110
+ result_ = o_
1111
+ break
1112
+ }
1113
+ }
1114
+ } while(false)
1115
+ };
1116
+ return result_
1117
+ } finally {
1118
+ (await self_.close_($task))
1119
+ }
1120
+ }
1121
+
1122
+ export async function Stream_grabFirst$(self_, $task) {
1123
+ return ff_core_Option.Option_else((await ff_core_Stream.Stream_first$(self_, $task)), (() => {
1124
+ return ff_core_Core.panic_("grabFirst() on empty iterator")
1125
+ }))
1126
+ }
1127
+
1128
+ export async function Stream_grabLast$(self_, $task) {
1129
+ return ff_core_Option.Option_else((await ff_core_Stream.Stream_last$(self_, $task)), (() => {
1130
+ return ff_core_Core.panic_("grabLast() on empty iterator")
1131
+ }))
1132
+ }
1133
+
1134
+ export async function Stream_collectFirst$(self_, body_, $task) {
1135
+ try {
1136
+ let done_ = false;
1137
+ let result_ = ff_core_Option.None();
1138
+ while((!done_)) {
1139
+ do {
1140
+ const _1 = (await self_.next_($task));
1141
+ {
1142
+ if(_1.None) {
1143
+ done_ = true
1144
+ break
1145
+ }
1146
+ }
1147
+ {
1148
+ if(_1.Some) {
1149
+ const x_ = _1.value_;
1150
+ do {
1151
+ const _1 = (await body_(x_, $task));
1152
+ {
1153
+ if(_1.None) {
1154
+
1155
+ break
1156
+ }
1157
+ }
1158
+ {
1159
+ const o_ = _1;
1160
+ done_ = true;
1161
+ result_ = o_
1162
+ break
1163
+ }
1164
+ } while(false)
1165
+ break
1166
+ }
1167
+ }
1168
+ } while(false)
1169
+ };
1170
+ return result_
1171
+ } finally {
1172
+ (await self_.close_($task))
1173
+ }
1174
+ }
1175
+
1176
+ export async function Stream_find$(self_, body_, $task) {
1177
+ return (await ff_core_Stream.Stream_first$((await ff_core_Stream.Stream_filter$(self_, body_, $task)), $task))
1178
+ }
1179
+
1180
+ export async function Stream_foldLeft$(self_, initial_, body_, $task) {
1181
+ let result_ = initial_;
1182
+ (await ff_core_Stream.Stream_each$(self_, (async (_w1, $task) => {
1183
+ result_ = (await body_(result_, _w1, $task))
1184
+ }), $task));
1185
+ return result_
1186
+ }
1187
+
1188
+ export async function Stream_toStack$(self_, $task) {
1189
+ const stack_ = ff_core_Stack.make_();
1190
+ (await ff_core_Stream.Stream_each$(self_, (async (_w1, $task) => {
1191
+ ff_core_Stack.Stack_push(stack_, _w1)
1192
+ }), $task));
1193
+ return stack_
1194
+ }
1195
+
1196
+ export async function Stream_toArray$(self_, $task) {
1197
+ return ff_core_Stack.Stack_drain((await ff_core_Stream.Stream_toStack$(self_, $task)))
1198
+ }
1199
+
1200
+ export async function Stream_toList$(self_, $task) {
1201
+ return ff_core_Stack.Stack_toList((await ff_core_Stream.Stream_toStack$(self_, $task)), 0, 9007199254740991)
1202
+ }
1203
+
1204
+ export function Stream_flatten(self_) {
1205
+ return ff_core_Stream.Stream_flatMap(self_, ((_w1) => {
1206
+ return _w1
1207
+ }))
1208
+ }
1209
+
1210
+ export async function Stream_flatten$(self_, $task) {
1211
+ return (await ff_core_Stream.Stream_flatMap$(self_, (async (_w1, $task) => {
1212
+ return _w1
1213
+ }), $task))
1214
+ }
1215
+
1216
+ export function Stream_toSet(self_, ff_core_Ordering_Order$T) {
1217
+ return ff_core_Array.Array_toSet(ff_core_Stream.Stream_toArray(self_), ff_core_Ordering_Order$T)
1218
+ }
1219
+
1220
+ export async function Stream_toSet$(self_, ff_core_Ordering_Order$T, $task) {
1221
+ return ff_core_Array.Array_toSet((await ff_core_Stream.Stream_toArray$(self_, $task)), ff_core_Ordering_Order$T)
1222
+ }
1223
+
1224
+ export function Stream_toMap(self_, ff_core_Ordering_Order$K) {
1225
+ return ff_core_Array.Array_toMap(ff_core_Stream.Stream_toArray(self_), ff_core_Ordering_Order$K)
1226
+ }
1227
+
1228
+ export async function Stream_toMap$(self_, ff_core_Ordering_Order$K, $task) {
1229
+ return ff_core_Array.Array_toMap((await ff_core_Stream.Stream_toArray$(self_, $task)), ff_core_Ordering_Order$K)
1230
+ }
1231
+
1232
+ export function Stream_toBuffer(self_) {
1233
+ const builder_ = ff_core_Stack.make_();
1234
+ ff_core_Stream.Stream_each(self_, ((_w1) => {
1235
+ ff_core_Stack.Stack_push(builder_, _w1)
1236
+ }));
1237
+ return ff_core_Buffer.fromBufferArray_(ff_core_Stack.Stack_drain(builder_))
1238
+ }
1239
+
1240
+ export function Stream_toString(self_, encoding_ = "utf8") {
1241
+ return ff_core_Buffer.Buffer_toString(ff_core_Stream.Stream_toBuffer(self_), encoding_)
1242
+ }
1243
+
1244
+ export function Stream_readBytes(self_, bytes_) {
1245
+ if((bytes_ <= 0)) {
1246
+ return ff_core_Pair.Pair(ff_core_List.List_toArray(ff_core_List.Empty()), self_)
1247
+ } else {
1248
+ const buffers_ = ff_core_Stack.make_();
1249
+ let buffer_ = ff_core_Option.Option_grab(self_.next_());
1250
+ let taken_ = 0;
1251
+ let remainder_ = ff_core_Option.None();
1252
+ while(ff_core_Option.ff_core_Equal_Equal$ff_core_Option_Option(ff_core_Buffer.ff_core_Equal_Equal$ff_core_Buffer_Buffer).equals_(remainder_, ff_core_Option.None())) {
1253
+ const needed_ = (bytes_ - taken_);
1254
+ if((needed_ > ff_core_Buffer.Buffer_size(buffer_))) {
1255
+ ff_core_Stack.Stack_push(buffers_, buffer_);
1256
+ taken_ += ff_core_Buffer.Buffer_size(buffer_);
1257
+ buffer_ = ff_core_Option.Option_grab(self_.next_())
1258
+ } else {
1259
+ ff_core_Stack.Stack_push(buffers_, ff_core_Buffer.Buffer_view(buffer_, 0, needed_));
1260
+ remainder_ = ff_core_Option.Some(ff_core_Buffer.Buffer_view(buffer_, needed_, ff_core_Buffer.Buffer_size(buffer_)))
1261
+ }
1262
+ };
1263
+ return ff_core_Pair.Pair(ff_core_Stack.Stack_drain(buffers_), ff_core_Stream.Stream_addAll(ff_core_Option.Option_toStream(remainder_, false), self_))
1264
+ }
1265
+ }
1266
+
1267
+ export async function Stream_toBuffer$(self_, $task) {
1268
+ const builder_ = ff_core_Stack.make_();
1269
+ (await ff_core_Stream.Stream_each$(self_, (async (_w1, $task) => {
1270
+ ff_core_Stack.Stack_push(builder_, _w1)
1271
+ }), $task));
1272
+ return ff_core_Buffer.fromBufferArray_(ff_core_Stack.Stack_drain(builder_))
1273
+ }
1274
+
1275
+ export async function Stream_toString$(self_, encoding_ = "utf8", $task) {
1276
+ return ff_core_Buffer.Buffer_toString((await ff_core_Stream.Stream_toBuffer$(self_, $task)), encoding_)
1277
+ }
1278
+
1279
+ export async function Stream_readBytes$(self_, bytes_, $task) {
1280
+ if((bytes_ <= 0)) {
1281
+ return ff_core_Pair.Pair(ff_core_List.List_toArray(ff_core_List.Empty()), self_)
1282
+ } else {
1283
+ const buffers_ = ff_core_Stack.make_();
1284
+ let buffer_ = ff_core_Option.Option_grab((await self_.next_($task)));
1285
+ let taken_ = 0;
1286
+ let remainder_ = ff_core_Option.None();
1287
+ while(ff_core_Option.ff_core_Equal_Equal$ff_core_Option_Option(ff_core_Buffer.ff_core_Equal_Equal$ff_core_Buffer_Buffer).equals_(remainder_, ff_core_Option.None())) {
1288
+ const needed_ = (bytes_ - taken_);
1289
+ if((needed_ > ff_core_Buffer.Buffer_size(buffer_))) {
1290
+ ff_core_Stack.Stack_push(buffers_, buffer_);
1291
+ taken_ += ff_core_Buffer.Buffer_size(buffer_);
1292
+ buffer_ = ff_core_Option.Option_grab((await self_.next_($task)))
1293
+ } else {
1294
+ ff_core_Stack.Stack_push(buffers_, ff_core_Buffer.Buffer_view(buffer_, 0, needed_));
1295
+ remainder_ = ff_core_Option.Some(ff_core_Buffer.Buffer_view(buffer_, needed_, ff_core_Buffer.Buffer_size(buffer_)))
1296
+ }
1297
+ };
1298
+ return ff_core_Pair.Pair(ff_core_Stack.Stack_drain(buffers_), (await ff_core_Stream.Stream_addAll$((await ff_core_Option.Option_toStream$(remainder_, false, $task)), self_, $task)))
1299
+ }
1300
+ }
1301
+
1302
+
1303
+
1304
+