File tree Expand file tree Collapse file tree 2 files changed +27
-27
lines changed Expand file tree Collapse file tree 2 files changed +27
-27
lines changed Original file line number Diff line number Diff line change @@ -148,33 +148,6 @@ def x{ body: => Unit / { literal, HexSplices } }: Int = {
148
148
res
149
149
}
150
150
151
- // Counting and padding
152
- // --------------------
153
- // TODO could also be part of stream library
154
-
155
- /// get current position in stream
156
- effect getPos(): Int
157
-
158
- /// Track position in stream, starting with init
159
- /// Handles getPos and pad
160
- def tracking[A](init: Int){ body: => Unit / { emit[A], getPos } }: Unit / emit[A] = {
161
- var n = init
162
- try body()
163
- with emit[A] { b => n = n + 1; resume(do emit[A](b)) }
164
- with getPos{ resume(n) }
165
- }
166
-
167
- /// Pad to a multiple of fac, by calling gen for each
168
- def pad[A](fac: Int){ gen: => A }: Unit / {getPos, emit[A]} = {
169
- while(mod(do getPos(), fac) != 0) {
170
- do emit[A](gen())
171
- }
172
- }
173
-
174
- /// Track how many bytes were emitted
175
- /// Handles getPos and pad
176
- def tracking[A]{ body: => Unit / { emit[A], getPos } }: Unit / emit[A] =
177
- tracking[A](0){body}
178
151
179
152
// Sub-Byte
180
153
// ========
Original file line number Diff line number Diff line change @@ -504,6 +504,33 @@ def tee[A]{ cons1: { => Unit / emit[A] } => Unit }{ cons2: { => Unit / emit[A] }
504
504
}
505
505
}
506
506
507
+ // Counting and padding
508
+ // --------------------
509
+
510
+ /// get current position in stream
511
+ effect getPos(): Int
512
+
513
+ /// Track position in stream, starting with init
514
+ /// Handles getPos
515
+ def tracking[A](init: Int){ body: => Unit / { emit[A], getPos } }: Unit / emit[A] = {
516
+ var n = init
517
+ try body()
518
+ with emit[A] { b => n = n + 1; resume(do emit[A](b)) }
519
+ with getPos{ resume(n) }
520
+ }
521
+
522
+ /// Pad to a multiple of fac emitted values, by emitting gen repeatedly
523
+ def pad[A](fac: Int){ gen: => A }: Unit / {getPos, emit[A]} = {
524
+ while(mod(do getPos(), fac) != 0) {
525
+ do emit[A](gen())
526
+ }
527
+ }
528
+
529
+ /// Track how many bytes were emitted (in the body)
530
+ /// Handles getPos
531
+ def tracking[A]{ body: => Unit / { emit[A], getPos } }: Unit / emit[A] =
532
+ tracking[A](0){body}
533
+
507
534
namespace returning {
508
535
509
536
/// Canonical handler of push streams that performs `action` for every
You can’t perform that action at this time.
0 commit comments