-
Notifications
You must be signed in to change notification settings - Fork 29
/
If.scala
40 lines (38 loc) · 1.15 KB
/
If.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
38
39
40
package com.thoughtworks.dsl
package keywords
import Dsl.IsKeyword
import Dsl.cpsApply
final case class If[+ConditionKeyword, +ThenKeyword, +ElseKeyword](
cond: ConditionKeyword,
thenp: () => ThenKeyword,
elsep: () => ElseKeyword
) extends Dsl.Keyword.Trait
object If {
given [ConditionKeyword, ThenKeyword, ThenValue, ElseKeyword, ElseValue](using
IsKeyword[ThenKeyword, ThenValue],
IsKeyword[ElseKeyword, ElseValue]
): IsKeyword[
If[ConditionKeyword, ThenKeyword, ElseKeyword],
ThenValue | ElseValue
] with {}
given [ConditionKeyword, ThenKeyword, ElseKeyword, Domain, Value](using
Dsl.Searching[ConditionKeyword, Domain, Boolean],
Dsl.Searching[ThenKeyword, Domain, Value],
Dsl.Searching[ElseKeyword, Domain, Value]
): Dsl.Composed[If[
ConditionKeyword,
ThenKeyword,
ElseKeyword
], Domain, Value] = Dsl.Composed {
(
keyword: If[ConditionKeyword, ThenKeyword, ElseKeyword],
handler: Value => Domain
) =>
keyword.cond.cpsApply {
case true =>
keyword.thenp().cpsApply(handler)
case false =>
keyword.elsep().cpsApply(handler)
}
}
}