Skip to content

Commit 55b5913

Browse files
committed
Implement zip (nested/nested)
1 parent 6444437 commit 55b5913

File tree

2 files changed

+27
-10
lines changed

2 files changed

+27
-10
lines changed

tests/run-with-compiler-custom-args/staged-streams_1.check

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,6 @@
1414

1515
15
1616

17-
15
17+
15
18+
19+
36

tests/run-with-compiler-custom-args/staged-streams_1.scala

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ object Test {
2121
}
2222
}
2323

24-
type Id[A] = A
25-
2624
trait Producer[A] { self =>
2725
type St
2826
val card: Cardinality
@@ -356,10 +354,12 @@ object Test {
356354
}
357355
else {
358356
~currentAdvance.update('{oldAdvance})
357+
oldAdvance(_)
359358
}
360-
~currentAdvance.update('{newAdvance})
361-
newAdvance(_)
362359
}}
360+
361+
~currentAdvance.update('{newAdvance})
362+
newAdvance(_)
363363
})
364364
}
365365
case nested: Nested[A, bt] =>
@@ -379,7 +379,7 @@ object Test {
379379
Var('{ (_: Unit) => ()}){ advf => {
380380
Var('{ true }) { hasNext => {
381381
Var('{ null.asInstanceOf[A] }) { curr => '{
382-
val adv: Unit => Unit = { _ =>
382+
def adv: Unit => Unit = { _ =>
383383
~hasNext.update(producer.hasNext(st))
384384
if(~hasNext.get) {
385385
~producer.step(st, el => makeAdvanceFunction[Expr[A]](advf, (a => curr.update(a)), nestedf(el)))
@@ -395,9 +395,19 @@ object Test {
395395
}})
396396
}
397397

398-
def step(st: St, k: Expr[A] => Expr[Unit]): Expr[Unit] = ???
398+
def step(st: St, k: Expr[A] => Expr[Unit]): Expr[Unit] = {
399+
val (flag, current, advf) = st
400+
var el: Var[A] = current
401+
val f: Expr[Unit => Unit] = advf.get
402+
403+
f('())
404+
k((el.get))
405+
}
399406

400-
def hasNext(st: St): Expr[Boolean] = ???
407+
def hasNext(st: St): Expr[Boolean] = {
408+
val (flag, _, _) = st
409+
flag.get
410+
}
401411
}
402412
}
403413
}
@@ -460,9 +470,7 @@ object Test {
460470
}
461471

462472
def zip[B: Type, C: Type](f: (Expr[A] => Expr[B] => Expr[C]), stream2: Stream[B]): Stream[C] = {
463-
464473
val Stream(stream_b) = stream2
465-
466474
Stream(mapRaw[(Expr[A], Expr[B]), Expr[C]]((t => k => '{ ~k(f(t._1)(t._2)) }), zipRaw[A, Expr[B]](stream, stream_b)))
467475
}
468476
}
@@ -548,6 +556,11 @@ object Test {
548556
.zip(((a : Expr[Int]) => (b : Expr[Int]) => '{ ~a + ~b }), Stream.of('{Array(1, 2, 3)}) )
549557
.fold('{0}, ((a: Expr[Int], b : Expr[Int]) => '{ ~a + ~b }))
550558

559+
def test10() = Stream
560+
.of('{Array(1, 2, 3)}).flatMap((d: Expr[Int]) => Stream.of('{Array(1, 2, 3)}).map((dp: Expr[Int]) => '{ ~d + ~dp }))
561+
.zip(((a : Expr[Int]) => (b : Expr[Int]) => '{ ~a + ~b }), Stream.of('{Array(1, 2, 3)}).flatMap((d: Expr[Int]) => Stream.of('{Array(1, 2, 3)}).map((dp: Expr[Int]) => '{ ~d + ~dp })) )
562+
.fold('{0}, ((a: Expr[Int], b : Expr[Int]) => '{ ~a + ~b }))
563+
551564
def main(args: Array[String]): Unit = {
552565
println(test1().run)
553566
println
@@ -566,6 +579,8 @@ object Test {
566579
println(test8().run)
567580
println
568581
println(test9().run)
582+
println
583+
println(test10().run)
569584
}
570585
}
571586

0 commit comments

Comments
 (0)