Access to Gen in Prog.around

This commit is contained in:
alari 2021-03-13 11:11:34 +03:00
parent d7e81256ae
commit 5306514e92
4 changed files with 7 additions and 7 deletions

View File

@ -14,10 +14,10 @@ case class RunAfter[Alg[_], A](prog: Free[Alg, A]) extends Prog[Alg, A] {
}
case class RunAround[Alg[_], R, A](before: Free[Alg, R], after: R => Free[Alg, A]) extends Prog[Alg, A] {
case class RunAround[Alg[_], R, A](before: Free[Alg, R], after: (R, A) => Free[Alg, A]) extends Prog[Alg, A] {
override def apply(v1: Free[Alg, A]): Free[Alg, A] =
before >>= (a => v1 >> after(a))
before >>= (r => v1 >>= (a => after(r, a)))
}
object Prog {
@ -28,7 +28,7 @@ object Prog {
def after[Alg[_], A](prog: Free[Alg, A]): Prog[Alg, A] =
RunAfter(prog)
def around[Alg[_], R, A](before: Free[Alg, R], after: R => Free[Alg, A]): Prog[Alg, A] =
def around[Alg[_], R, A](before: Free[Alg, R], after: (R, A) => Free[Alg, A]): Prog[Alg, A] =
RunAround(before, after)
}

View File

@ -48,9 +48,9 @@ case class FuncExpr[F[_]](name: Name[F], args: List[Arg[F]], ret: Option[DataTyp
ret.fold(Free.pure[Alg, Option[Type]](None))(T.resolveType(_).map(Some(_)))
)
.map(argsAndRes => ArrowType(argsAndRes._1, argsAndRes._2)),
(funcArrow: ArrowType) =>
(funcArrow: ArrowType, bodyGen: Gen) =>
// Erase arguments and internal variables
A.endScope() >> N.endScope() >> N.define(name, funcArrow) as Gen("Function defined")
A.endScope() >> N.endScope() >> N.define(name, funcArrow) as Gen("Function defined, wrap + " + bodyGen)
)
}

View File

@ -21,7 +21,7 @@ case class OnExpr[F[_]](peerId: Value[F]) extends Expr[F] {
): Prog[Alg, Gen] =
Prog.around(
V.ensureIsString(peerId) >> P.onPeerId(peerId) >> A.beginScope(peerId),
(_: Unit) => A.endScope() >> P.erasePeerId() as Gen("OnScope finished")
(_: Unit, ops: Gen) => A.endScope() >> P.erasePeerId() as Gen("OnScope finished for" + ops)
)
}

View File

@ -27,7 +27,7 @@ case class ServiceExpr[F[_]](name: Ability[F], id: Option[Value[F]]) extends Exp
): Prog[Alg, Gen] =
Prog.around(
A.beginScope(name),
(_: Unit) =>
(_: Unit, body: Gen) =>
(A.purgeArrows(name) <* A.endScope()).flatMap {
case Some(nel) =>
A.defineService(name, nel.map(kv => kv._1.name.extract -> kv._2).toNem) >>