Skip to content

Commit 27c8a41

Browse files
authored
Merge pull request #494 from Atry/cast-to-apply
Rename cast to apply
2 parents 46d1edf + 92d7a33 commit 27c8a41

File tree

14 files changed

+30
-50
lines changed
  • Dsl/src/main/scala/com/thoughtworks/dsl
  • bangnotation/src/main/scala/com/thoughtworks/dsl
  • comprehension/src/main/scala/com/thoughtworks/dsl
  • domains-scalaz/src/main/scala/com/thoughtworks/dsl/domains
  • keywords-Await/src/main/scala/com/thoughtworks/dsl/keywords
  • keywords-ForYield/src/main/scala/com/thoughtworks/dsl/keywords
  • keywords-In/src/main/scala/com/thoughtworks/dsl/keywords
  • keywords-Monadic/src/main/scala/com/thoughtworks/dsl/keywords
  • keywords-Pure/src/main/scala/com/thoughtworks/dsl/keywords
  • keywords-Return/src/main/scala/com/thoughtworks/dsl/keywords
  • keywords-Shift/src/main/scala/com/thoughtworks/dsl/keywords
  • keywords-Suspend/src/main/scala/com/thoughtworks/dsl/keywords
  • keywords-Using/src/main/scala/com/thoughtworks/dsl/keywords
  • keywords-Yield/src/main/scala/com/thoughtworks/dsl/keywords

14 files changed

+30
-50
lines changed

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -515,9 +515,7 @@ object Dsl extends LowPriorityDsl0 {
515515
@inline def withValueType: Typed[Keyword, NewValue] = typedKeyword
516516
}
517517

518-
@inline def cast[Keyword, Value]: Keyword =:= Typed[Keyword, Value] = summon[Keyword =:= Typed[Keyword, Value]]
519-
520-
def apply[Keyword, Value](keyword: Keyword): Typed[Keyword, Value] = keyword
518+
@inline def apply[Keyword, Value]: Keyword =:= Typed[Keyword, Value] = summon
521519

522520
}
523521

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ object bangnotation {
6565
val reifiedTerm = KeywordTree(bodyTerm).keywordTerm
6666
reifiedTerm.usingExpr { [K] => (k: quoted.Expr[K]) => (tk: quoted.Type[K]) =>
6767
given quoted.Type[K] = tk
68-
'{Dsl.Typed.cast[K, V]($k)}: quoted.Expr[_]
68+
'{Dsl.Typed[K, V]($k)}: quoted.Expr[_]
6969
}
7070
}
7171

@@ -703,7 +703,7 @@ object bangnotation {
703703
valueType/*.widenTermRefByName*/.usingType { [A] => (ta: quoted.Type[A]) =>
704704
given quoted.Type[A] = ta
705705
'{
706-
keywords.Pure.cast[A](${term.asExprOf[A]})
706+
keywords.Pure[A](${term.asExprOf[A]})
707707
}.asTerm
708708
}
709709
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ extension [Keyword, Value](keyword: Keyword)
2626
)(
2727
mapper: Value => MappedValue
2828
): FlatMap[Keyword, Value, Pure[MappedValue]] =
29-
FlatMap(keyword, Pure.cast.liftCo(mapper))
29+
FlatMap(keyword, Pure.apply.liftCo(mapper))
3030

3131
@inline def flatMap[Mapped, MappedValue](
3232
using /*erased*/ AsKeyword.FromKeyword[Keyword, Value]

domains-scalaz/src/main/scala/com/thoughtworks/dsl/domains/scalaz.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ object scalaz {
218218
implicit def scalazMonadicDsl[F[_], A, B](implicit bind: Bind[F]): Dsl[Monadic[F, A], F[B], A] =
219219
new Dsl[Monadic[F, A], F[B], A] {
220220
def cpsApply(keyword: Monadic[F, A], handler: A => F[B]): F[B] = {
221-
bind.bind(Monadic.cast.flip(keyword))(handler)
221+
bind.bind(Monadic.apply.flip(keyword))(handler)
222222
}
223223
}
224224

@@ -228,7 +228,7 @@ object scalaz {
228228
def lift(fa: F[A]): G[A]
229229

230230
final def cpsApply(keyword: Monadic[F, A], handler: A => G[B]): G[B] = {
231-
monad.bind(lift(Monadic.cast.flip(keyword)))(handler)
231+
monad.bind(lift(Monadic.apply.flip(keyword)))(handler)
232232
}
233233

234234
}

keywords-Await/src/main/scala/com/thoughtworks/dsl/keywords/Await.scala

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -109,17 +109,15 @@ import scala.language.implicitConversions
109109
*/
110110
opaque type Await[Result] = concurrent.Future[Result]
111111
object Await {
112-
extension [Result](keyword: Await[Result]) def future: concurrent.Future[Result] = keyword
113-
def apply[Result](future: concurrent.Future[Result]): Await[Result] = future
114-
@inline def cast[Result]: concurrent.Future[Result] <:< Await[Result] = implicitly
112+
@inline def apply[Result]: concurrent.Future[Result] =:= Await[Result] = summon
115113
given [Result]: AsKeyword.FromKeyword[Await[Result], Result] with {}
116114

117115
implicit def streamAwaitDsl[Value, That](implicit
118116
executionContext: ExecutionContext
119117
): Dsl[Await[Value], Stream[Future[That]], Value] =
120118
new Dsl[Await[Value], Stream[Future[That]], Value] {
121119
def cpsApply(keyword: Await[Value], handler: Value => Stream[Future[That]]): Stream[Future[That]] = {
122-
val futureOfStream = keyword.future.map(handler)
120+
val futureOfStream = keyword.map(handler)
123121
new Stream.Cons(futureOfStream.flatMap(_.head), result(futureOfStream, Duration.Inf).tail)
124122
}
125123
}
@@ -129,7 +127,7 @@ object Await {
129127
): Dsl[Await[Value], Future[That], Value] =
130128
new Dsl[Await[Value], Future[That], Value] {
131129
def cpsApply(keyword: Await[Value], handler: Value => Future[That]): Future[That] = {
132-
keyword.future.flatMap(handler)
130+
keyword.flatMap(handler)
133131
}
134132
}
135133

@@ -143,7 +141,7 @@ object Await {
143141
): Dsl[Await[Value], Unit !! Throwable, Value] =
144142
new Dsl[Await[Value], Unit !! Throwable, Value] {
145143
def cpsApply(keyword: Await[Value], handler: Value => Unit !! Throwable): Unit !! Throwable =
146-
!!.fromTryContinuation[Unit, Value](keyword.future.onComplete)(handler)
144+
!!.fromTryContinuation[Unit, Value](keyword.onComplete)(handler)
147145
}
148146

149147
given [Value]: AsKeyword.FromKeywordSubtype[Future[Value], Await[Value], Value] with {}

keywords-ForYield/src/main/scala/com/thoughtworks/dsl/keywords/ForYield.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ import Dsl.Typed
88

99
opaque type ForYield[Keyword, AsKeyword.FromKeyword, OutputValue] = Dsl.Typed[Keyword, AsKeyword.FromKeyword]
1010
object ForYield {
11-
@inline def cast[Keyword, AsKeyword.FromKeyword, OutputValue]: Dsl.Typed[Keyword, AsKeyword.FromKeyword] <:< ForYield[Keyword, AsKeyword.FromKeyword, OutputValue] = implicitly
11+
@inline def apply[Keyword, AsKeyword.FromKeyword, OutputValue]: Dsl.Typed[Keyword, AsKeyword.FromKeyword] =:= ForYield[Keyword, AsKeyword.FromKeyword, OutputValue] = summon
1212
}

keywords-In/src/main/scala/com/thoughtworks/dsl/keywords/In.scala

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@ package keywords
33
import Dsl.AsKeyword
44
import Dsl.Typed
55

6-
opaque type In[Element] <: Any = Iterable[Element]
6+
opaque type In[Element] = Iterable[Element]
77
object In {
8-
@inline def cast[Element]: Iterable[Element] <:< In[Element] = implicitly
9-
def apply[Element](iterable: Iterable[Element]): In[Element] = iterable
8+
@inline def apply[Element]: Iterable[Element] =:= In[Element] = summon
109

1110
given [Element]: AsKeyword.FromKeyword[In[Element], Element] with {}
1211

keywords-Monadic/src/main/scala/com/thoughtworks/dsl/keywords/Monadic.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ import scala.language.implicitConversions
1818
opaque type Monadic[Functor[_], Value] <: Any = Functor[Value]
1919

2020
object Monadic {
21-
@inline def cast[Functor[_], Value]: Functor[Value] =:= Monadic[Functor, Value] = implicitly
22-
@inline def apply[Functor[_], Value](f: Functor[Value]): Monadic[Functor, Value] = f
21+
@inline def apply[Functor[_], Value]: Functor[Value] =:= Monadic[Functor, Value] = summon
2322

2423
given [Functor[_], Value]: AsKeyword.FromKeyword[Monadic[Functor, Value], Value] with {}
2524

keywords-Pure/src/main/scala/com/thoughtworks/dsl/keywords/Pure.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,5 @@ object Pure {
1212
}
1313

1414
given [PureValue]: AsKeyword.FromKeyword[Pure[PureValue], PureValue] with {}
15-
@inline def cast[Value]: Value =:= Pure[Value] = summon[Value =:= Pure[Value]]
16-
def apply[Value](value: Value): Pure[Value] = value
15+
@inline def apply[Value]: Value =:= Pure[Value] = summon[Value =:= Pure[Value]]
1716
}

keywords-Return/src/main/scala/com/thoughtworks/dsl/keywords/Return.scala

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,10 @@ import Dsl.Typed
1515
*/
1616
opaque type Return[ReturnValue] = ReturnValue
1717
object Return {
18-
@inline def cast[ReturnValue]: ReturnValue <:< Return[ReturnValue] = implicitly
18+
@inline def apply[ReturnValue]: ReturnValue =:= Return[ReturnValue] = summon
1919

20-
@inline def apply[ReturnValue]: ReturnValue =:= Return[ReturnValue] = summon[ReturnValue =:= Return[ReturnValue]]
2120
given [ReturnValue]: AsKeyword.FromKeyword[Return[ReturnValue], Nothing] with {}
2221

23-
extension [ReturnValue](keyword: Return[ReturnValue]) def returnValue: ReturnValue = keyword
24-
2522
given [ReturnValue, Domain](using
2623
lift: Lift[ReturnValue, Domain]
2724
): Dsl[Return[ReturnValue], Domain, Nothing] with {
@@ -33,7 +30,7 @@ object Return {
3330
implicit def returnDsl[ReturnValue, Domain >: ReturnValue]: Dsl[Return[ReturnValue], Domain, Nothing] =
3431
new Dsl[Return[ReturnValue], Domain, Nothing] {
3532
def cpsApply(keyword: Return[ReturnValue], handler: Nothing => Domain): Domain = {
36-
keyword.returnValue
33+
keyword
3734
}
3835
}
3936
}

0 commit comments

Comments
 (0)