-
Notifications
You must be signed in to change notification settings - Fork 29
/
Return.scala
41 lines (33 loc) · 1.11 KB
/
Return.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
41
package com.thoughtworks.dsl
package keywords
import com.thoughtworks.dsl.Dsl
import scala.language.implicitConversions
import Dsl.IsKeyword
import Dsl.Lift
/** A [[Dsl.Keyword]] to early return a lifted value from the enclosing
* function.
*
* @author
* 杨博 (Yang Bo)
*/
opaque type Return[+ReturnValue] <: Dsl.Keyword.Opaque =
Dsl.Keyword.Opaque.Of[ReturnValue]
@inline def Return[ReturnValue](using
dummyImplicit: DummyImplicit = DummyImplicit.dummyImplicit
): ReturnValue =:= Return[ReturnValue] =
Dsl.Keyword.Opaque.Of
object Return {
given [ReturnValue]: IsKeyword[Return[ReturnValue], Nothing] with {}
given [ReturnValue, Domain](using
lift: Lift[ReturnValue, Domain]
): Dsl.Original[Return[ReturnValue], Domain, Nothing] = Dsl.Original {
(keyword: Return[ReturnValue], handler: Nothing => Domain) =>
lift(keyword)
}
given [ReturnValue, Domain >: ReturnValue]
: Dsl.Original[Return[ReturnValue], Domain, Nothing] =
Dsl.Original[Return[ReturnValue], Domain, Nothing] {
(keyword: Return[ReturnValue], handler: Nothing => Domain) =>
keyword
}
}