Skip to content

Commit

Permalink
Use fold instead of map+getOrElse
Browse files Browse the repository at this point in the history
  • Loading branch information
aztek committed Jun 24, 2014
1 parent e4ed918 commit 53954b2
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/main/scala/scala/workflow/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -201,20 +201,24 @@ package object workflow extends Instances {
val (newscope, newexpr) = rewrite(scope.enter)(expr)
val frame = newscope.materialized.last
if (frame.isEmpty) {
val name = signature map { case (_, name, _) name } getOrElse TermName("_")
val name = signature.fold(TermName("_")) {
case (_, name, _) name
}
val tpe = typeCheck(newexpr, newscope).get.tpe
val bind = Bind(name, TypeTree(tpe), newexpr)
val cont = (_: Boolean) signature map {
case (mods, _, tpt) block(ValDef(mods, name, tpt, newexpr))
} getOrElse block(q"$newexpr")
val cont = (_: Boolean) signature.fold(block(q"$newexpr")) {
case (mods, _, tpt) block(ValDef(mods, name, tpt, newexpr))
}

val newerscope = if (signature.isDefined) scope :+ bind else scope

(newerscope ++ newscope.frames.head, cont)
} else {
val value = apply(frame)(newexpr)
val tpe = typeCheck(newexpr, newscope).get.tpe
val name = signature map { case (_, term, _) term } getOrElse TermName("_")
val name = signature.fold(TermName("_")) {
case (_, name, _) name
}
val bind = Bind(name, TypeTree(tpe), value)
val cont = (x: Boolean) if (x) >>=(bind) compose lambda(bind) // Especially dirty hack!
else map(bind) compose lambda(bind) // TODO: figure out a better way
Expand Down

0 comments on commit 53954b2

Please sign in to comment.