-
Notifications
You must be signed in to change notification settings - Fork 29
/
While.scala
37 lines (36 loc) · 923 Bytes
/
While.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package com.thoughtworks.dsl
package keywords
import Dsl.IsKeyword
import Dsl.cpsApply
case class While[
+ConditionKeyword,
+BodyKeyword
](
condition: () => ConditionKeyword,
body: () => BodyKeyword
) extends Dsl.Keyword.Trait
object While {
given [
ConditionKeyword,
BodyKeyword,
Domain
](using
conditionDsl: Dsl.Searching[ConditionKeyword, Domain, Boolean],
bodyDsl: Dsl.Searching[BodyKeyword, Domain, Any]
): Dsl.Composed[
While[ConditionKeyword, BodyKeyword],
Domain,
Unit
] = Dsl.Composed {
(keyword: While[ConditionKeyword, BodyKeyword], handler: Unit => Domain) =>
// TODO: Use Suspend to rewind the stack in case of stack overflow
keyword.condition().cpsApply {
case true =>
keyword.body().cpsApply { _ =>
keyword.cpsApply(handler)
}
case false =>
handler(())
}
}
}