File tree Expand file tree Collapse file tree 2 files changed +28
-29
lines changed Expand file tree Collapse file tree 2 files changed +28
-29
lines changed Original file line number Diff line number Diff line change @@ -280,35 +280,6 @@ def groupBytesLE{ body: => Unit / emit[Bit] }: Unit / emit[Byte] = {
280
280
def groupBytes{ body: => Unit / emit[Bit] }: Unit / emit[Byte] =
281
281
groupBytesBE{body}
282
282
283
- /// Return just nth element of the given stream.
284
- /// Raises MissingValue if not enough elements are emitted
285
- // TODO could be in stream
286
- def nth[A](n: Int){ body: => Unit / emit[A] }: A / Exception[MissingValue] = {
287
- var m = n
288
- try {
289
- body()
290
- val r: A = do raise[MissingValue](MissingValue(), "code in first did not emit any values")
291
- r
292
- } with emit[A] { a =>
293
- if (m == 0) {
294
- a
295
- } else {
296
- m = m - 1
297
- resume(())
298
- }
299
- }
300
- }
301
-
302
- /// Return just first element of the given stream.
303
- /// Raises MissingValue if no elements are emitted
304
- // TODO could be in stream
305
- def first[A]{ body: => Unit / emit[A] }: A / Exception[MissingValue] = {
306
- try {
307
- body()
308
- val r: A = do raise[MissingValue](MissingValue(), "code in first did not emit any values")
309
- r
310
- } with emit[A] { a => a }
311
- }
312
283
// Literals/splices
313
284
// ----------------
314
285
/// Splices allowed in bit stream literals
Original file line number Diff line number Diff line change @@ -531,6 +531,34 @@ def pad[A](fac: Int){ gen: => A }: Unit / {getPos, emit[A]} = {
531
531
def tracking[A]{ body: => Unit / { emit[A], getPos } }: Unit / emit[A] =
532
532
tracking[A](0){body}
533
533
534
+ /// Return just the nth element of the given stream.
535
+ /// Raises MissingValue if not enough elements are emitted
536
+ def nth[A](n: Int){ body: => Unit / emit[A] }: A / Exception[MissingValue] = {
537
+ var m = n
538
+ try {
539
+ body()
540
+ val r: A = do raise[MissingValue](MissingValue(), "code in first did not emit any values")
541
+ r
542
+ } with emit[A] { a =>
543
+ if (m == 0) {
544
+ a
545
+ } else {
546
+ m = m - 1
547
+ resume(())
548
+ }
549
+ }
550
+ }
551
+
552
+ /// Return just the first element of the given stream.
553
+ /// Raises MissingValue if no elements are emitted
554
+ def first[A]{ body: => Unit / emit[A] }: A / Exception[MissingValue] = {
555
+ try {
556
+ body()
557
+ val r: A = do raise[MissingValue](MissingValue(), "code in first did not emit any values")
558
+ r
559
+ } with emit[A] { a => a }
560
+ }
561
+
534
562
namespace returning {
535
563
536
564
/// Canonical handler of push streams that performs `action` for every
You can’t perform that action at this time.
0 commit comments