firefly-compiler 0.4.5 → 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 (78) hide show
  1. package/.hintrc +4 -4
  2. package/README.md +1 -1
  3. package/core/HttpClient.ff +1 -1
  4. package/lsp/LanguageServer.ff +32 -7
  5. package/lsp/stderr.txt +1 -0
  6. package/lsp/stdin.txt +11 -0
  7. package/lsp/stdout.txt +41 -0
  8. package/lux/Main.ff +56 -2
  9. package/meetup/AutoCompletion.ff +6 -0
  10. package/output/js/ff/compiler/Builder.mjs +444 -444
  11. package/output/js/ff/compiler/Compiler.mjs +416 -416
  12. package/output/js/ff/compiler/Dependencies.mjs +389 -389
  13. package/output/js/ff/compiler/Deriver.mjs +1170 -1170
  14. package/output/js/ff/compiler/Dictionaries.mjs +1309 -1309
  15. package/output/js/ff/compiler/Environment.mjs +1015 -1015
  16. package/output/js/ff/compiler/Inference.mjs +4268 -4268
  17. package/output/js/ff/compiler/JsEmitter.mjs +5391 -5391
  18. package/output/js/ff/compiler/JsImporter.mjs +266 -266
  19. package/output/js/ff/compiler/LspHook.mjs +793 -793
  20. package/output/js/ff/compiler/Main.mjs +1675 -1675
  21. package/output/js/ff/compiler/Parser.mjs +4008 -4008
  22. package/output/js/ff/compiler/Patterns.mjs +927 -927
  23. package/output/js/ff/compiler/Resolver.mjs +2307 -2307
  24. package/output/js/ff/compiler/Substitution.mjs +1150 -1150
  25. package/output/js/ff/compiler/Syntax.mjs +12434 -12434
  26. package/output/js/ff/compiler/Token.mjs +3096 -3096
  27. package/output/js/ff/compiler/Tokenizer.mjs +593 -593
  28. package/output/js/ff/compiler/Unification.mjs +1752 -1752
  29. package/output/js/ff/compiler/Wildcards.mjs +608 -608
  30. package/output/js/ff/compiler/Workspace.mjs +687 -687
  31. package/output/js/ff/core/Any.mjs +143 -143
  32. package/output/js/ff/core/Array.mjs +547 -547
  33. package/output/js/ff/core/AssetSystem.mjs +274 -274
  34. package/output/js/ff/core/Atomic.mjs +154 -154
  35. package/output/js/ff/core/Bool.mjs +152 -152
  36. package/output/js/ff/core/Box.mjs +112 -112
  37. package/output/js/ff/core/BrowserSystem.mjs +126 -126
  38. package/output/js/ff/core/Buffer.mjs +395 -395
  39. package/output/js/ff/core/BuildSystem.mjs +296 -296
  40. package/output/js/ff/core/Channel.mjs +189 -189
  41. package/output/js/ff/core/Char.mjs +149 -149
  42. package/output/js/ff/core/Core.mjs +300 -300
  43. package/output/js/ff/core/Duration.mjs +116 -116
  44. package/output/js/ff/core/Equal.mjs +179 -179
  45. package/output/js/ff/core/Error.mjs +142 -142
  46. package/output/js/ff/core/FileHandle.mjs +150 -150
  47. package/output/js/ff/core/Float.mjs +225 -225
  48. package/output/js/ff/core/HttpClient.mjs +190 -190
  49. package/output/js/ff/core/Instant.mjs +109 -109
  50. package/output/js/ff/core/Int.mjs +265 -265
  51. package/output/js/ff/core/IntMap.mjs +280 -280
  52. package/output/js/ff/core/JsSystem.mjs +238 -238
  53. package/output/js/ff/core/JsValue.mjs +708 -708
  54. package/output/js/ff/core/List.mjs +2334 -2334
  55. package/output/js/ff/core/Lock.mjs +229 -229
  56. package/output/js/ff/core/Log.mjs +163 -163
  57. package/output/js/ff/core/Map.mjs +362 -362
  58. package/output/js/ff/core/NodeSystem.mjs +294 -294
  59. package/output/js/ff/core/Nothing.mjs +104 -104
  60. package/output/js/ff/core/Option.mjs +1015 -1015
  61. package/output/js/ff/core/Ordering.mjs +730 -730
  62. package/output/js/ff/core/Pair.mjs +331 -331
  63. package/output/js/ff/core/Path.mjs +545 -545
  64. package/output/js/ff/core/RbMap.mjs +1940 -1940
  65. package/output/js/ff/core/Serializable.mjs +428 -428
  66. package/output/js/ff/core/Set.mjs +254 -254
  67. package/output/js/ff/core/Show.mjs +205 -205
  68. package/output/js/ff/core/SourceLocation.mjs +229 -229
  69. package/output/js/ff/core/Stack.mjs +529 -529
  70. package/output/js/ff/core/Stream.mjs +1304 -1304
  71. package/output/js/ff/core/String.mjs +365 -365
  72. package/output/js/ff/core/StringMap.mjs +280 -280
  73. package/output/js/ff/core/Task.mjs +320 -320
  74. package/output/js/ff/core/Try.mjs +507 -507
  75. package/output/js/ff/core/Unit.mjs +151 -151
  76. package/package.json +29 -29
  77. package/vscode/package-lock.json +5 -5
  78. package/vscode/package.json +1 -1
@@ -1,1304 +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_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
-
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
+