Skip to content

Commit 0618ce3

Browse files
committed
Add TrampolineFunction1
1 parent 7478d92 commit 0618ce3

File tree

1 file changed

+17
-8
lines changed
  • Dsl/src/main/scala/com/thoughtworks/dsl

1 file changed

+17
-8
lines changed

Dsl/src/main/scala/com/thoughtworks/dsl/Dsl.scala

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -125,22 +125,31 @@ object Dsl extends LowPriorityDsl0 {
125125
) => Domain
126126
) =:= Dsl[Keyword, Domain, Value] =
127127
summon
128-
129-
private[dsl] abstract class TrampolineContinuation[LeftDomain]
130-
extends (LeftDomain !! Throwable) {
131-
protected def step(): LeftDomain !! Throwable
132-
128+
private[dsl] abstract class TrampolineFunction1[-A, +R] extends (A => R) {
129+
protected def step(): A => R
133130
@tailrec
134-
private final def last(): LeftDomain !! Throwable = {
131+
protected final def last(): A => R = {
135132
step() match {
136-
case trampoline: TrampolineContinuation[LeftDomain] =>
133+
case trampoline: TrampolineFunction1[A, R] =>
137134
trampoline.last()
138135
case notTrampoline =>
139136
notTrampoline
140137
}
141138
}
142139

143-
final def apply(handler: Throwable => LeftDomain): LeftDomain = {
140+
def apply(state: A): R = {
141+
last()(state)
142+
}
143+
144+
}
145+
object TrampolineFunction1 {
146+
def apply[A, R](trampoline: TrampolineFunction1[A, R]) = trampoline
147+
}
148+
149+
private[dsl] abstract class TrampolineContinuation[LeftDomain]
150+
extends TrampolineFunction1[Throwable => LeftDomain, LeftDomain] {
151+
152+
override final def apply(handler: Throwable => LeftDomain): LeftDomain = {
144153
val protectedContinuation: LeftDomain !! Throwable =
145154
try {
146155
last()

0 commit comments

Comments
 (0)