8000 adopted do dotty-cps-async-0.9.6 · rssh/scala-gopher@107ffea · GitHub
[go: up one dir, main page]

Skip to content

Commit 107ffea

Browse files
committed
adopted do dotty-cps-async-0.9.6
1 parent 6245794 commit 107ffea

16 files changed

+61
-46
lines changed

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,16 @@
44

55
### Dependences:
66

7-
For scala 3:
7+
For scala 3.1.1+:
8+
9+
libraryDependencies += "com.github.rssh" %% "scala-gopher" % "3.0.0"
10+
11+
For scala 3 and 3.1.0:
812

913
libraryDependencies += "com.github.rssh" %% "scala-gopher" % "2.1.0"
1014

15+
Note, that 3.0.0 have no new functionality agains 2.1.0 but need to be a next major release because of binary incompability caused by difference between dotty-cps-async-0.9.5 and 0.9.6.
16+
1117
For scala2:
1218

1319
libraryDependencies += "com.github.rssh" %% "scala-gopher" % "0.99.15"

build.sbt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
//val dottyVersion = "3.0.0-RC2-bin-SNAPSHOT"
2-
val dottyVersion = "3.1.0"
2+
val dottyVersion = "3.1.1"
33
//val dottyVersion = dottyLatestNightlyBuild.get
44

5-
ThisBuild/version := "2.1.2-SNAPSHOT"
5+
ThisBuild/version := "3.0.0"
66
ThisBuild/versionScheme := Some("semver-spec")
77

88
val sharedSettings = Seq(
99
organization := "com.github.rssh",
1010
scalaVersion := dottyVersion,
1111
name := "scala-gopher",
1212
resolvers += "Local Ivy Repository" at "file://"+Path.userHome.absolutePath+"/.ivy2/local",
13-
libraryDependencies += "com.github.rssh" %%% "dotty-cps-async" % "0.9.4",
13+
libraryDependencies += "com.github.rssh" %%% "dotty-cps-async" % "0.9.6",
1414
libraryDependencies += "org.scalameta" %%% "munit" % "0.7.29" % Test,
1515
)
1616

@@ -45,7 +45,7 @@ lazy val gopher = crossProject(JSPlatform, JVMPlatform)
4545
Compile / doc / scalacOptions := Seq("-groups",
4646
"-source-links:shared=github://rssh/scala-gopher/master#shared",
4747
"-source-links:jvm=github://rssh/scala-gopher/master#jvm"),
48-
mimaPreviousArtifacts := Set( "com.github.rssh" %% "scala-gopher" % "2.1.0")
48+
mimaPreviousArtifacts := Set() //Set( "com.github.rssh" %% "scala-gopher" % "2.1.0")
4949
).jsSettings(
5050
libraryDependencies += ("org.scala-js" %%% "scalajs-java-logging" % "1.0.0").cross(CrossVersion.for3Use2_13),
5151
// TODO: switch to ModuleES ?

project/plugins.sbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ addSbtPlugin("com.jsuereth" % "sbt-pgp" % "2.0.2")
22
addSbtPlugin("com.typesafe.sbt" % "sbt-site" % "1.4.1")
33
addSbtPlugin("com.typesafe.sbt" % "sbt-ghpages" % "0.6.3")
44
addSbtPlugin("org.portable-scala" % "sbt-scalajs-crossproject" % "1.0.0")
5-
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.7.1")
5+
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.8.0")
66
addSbtPlugin("com.typesafe" % "sbt-mima-plugin" % "1.0.1")

shared/src/main/scala/gopher/Gopher.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ trait Gopher[F[_]:CpsSchedulingMonad]:
8383
}
8484

8585
end Gopher
86-
86+
8787

8888
/**
8989
* Create Read/Write channel.

shared/src/main/scala/gopher/ReadChannel.scala

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,12 @@ trait ReadChannel[F[_], A]:
5252
* Can be used only inside async block.
5353
* If stream is closed and no values to read left in the stream - throws StreamClosedException
5454
**/
55-
transparent inline def read(): A = await(aread())(using rAsyncMonad)
55+
transparent inline def read()(using CpsMonadContext[F]): A = await(aread())(using rAsyncMonad)
5656

5757
/**
5858
* Synonim for read.
5959
*/
60-
transparent inline def ? : A = await(aread())(using rAsyncMonad)
60+
transparent inline def ?(using CpsMonadContext[F]) : A = await(aread())(using rAsyncMonad)
6161

6262
/**
6363
* return F which contains sequence from first `n` elements.
@@ -83,7 +83,7 @@ trait ReadChannel[F[_], A]:
8383
* take first `n` elements.
8484
* should be called inside async block.
8585
**/
86-
transparent inline def take(n: Int): IndexedSeq[A] =
86+
transparent inline def take(n: Int)(using CpsMonadContext[F]): IndexedSeq[A] =
8787
await(atake(n))(using rAsyncMonad)
8888

8989
/**
@@ -107,7 +107,7 @@ trait ReadChannel[F[_], A]:
107107
*
108108
* should be called inside async block.
109109
**/
110-
transparent inline def optRead(): Option[A] = await(aOptRead())(using rAsyncMonad)
110+
transparent inline def optRead()(using CpsMonadContext[F]): Option[A] = await(aOptRead())(using rAsyncMonad)
111111

112112
def foreach_async(f: A=>F[Unit]): F[Unit] =
113113
given CpsAsyncMonad[F] = asyncMonad
@@ -130,7 +130,7 @@ trait ReadChannel[F[_], A]:
130130
* run code each time when new object is arriced.
131131
* until end of stream is not reached
132132
**/
133-
transparent inline def foreach(inline f: A=>Unit): Unit =
133+
transparent inline def foreach(inline f: A=>Unit)(using CpsMonadContext[F]): Unit =
134134
await(aforeach(f))(using rAsyncMonad)
135135

136136

@@ -170,8 +170,8 @@ trait ReadChannel[F[_], A]:
170170
s
171171
}
172172

173-
transparent inline def fold[S](inline s0:S)(inline f: (S,A) => S ): S =
174-
await[F,S](afold(s0)(f))(using rAsyncMonad)
173+
transparent inline def fold[S](inline s0:S)(inline f: (S,A) => E377 ; S )(using mc:CpsMonadContext[F]): S =
174+
await[F,S,F](afold(s0)(f))(using rAsyncMonad, mc)
175175

176176
def zip[B](x: ReadChannel[F,B]): ReadChannel[F,(A,B)] =
177177
given CpsSchedulingMonad[F] = asyncMonad
@@ -317,14 +317,18 @@ object ReadChannel:
317317
}
318318

319319

320-
320+
321321
import cps.stream._
322322

323-
given emitAbsorber[F[_]: CpsSchedulingMonad,T](using gopherApi: Gopher[F]): BaseUnfoldCpsAsyncEmitAbsorber[ReadChannel[F,T],F,T](
324-
using gopherApi.asyncMonad, gopherApi.taskExecutionContext) with
323+
given emitAbsorber[F[_], C<:CpsMonadContext[F], T](using auxMonad: CpsSchedulingMonad[F]{ type Context = C }, gopherApi: Gopher[F]): BaseUnfoldCpsAsyncEmitAbsorber[ReadChannel[F,T],F,C,T](
324+
using gopherApi.taskExecutionContext, auxMonad) with
325325

326326
override type Element = T
327327

328+
def asSync(fs: F[ReadChannel[F,T]]): ReadChannel[F,T] =
329+
DelayedReadChannel(fs)
330+
331+
328332
def unfold[S](s0:S)(f: S => F[Option[(T,S)]]): ReadChannel[F,T] =
329333
val r: ReadChannel[F,T] = unfoldAsync(s0)(f)
330334
r

shared/src/main/scala/gopher/Select.scala

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ class Select[F[_]](api: Gopher[F]):
2626
*}
2727
*```
2828
*/
29-
transparent inline def apply[A](inline pf: PartialFunction[Any,A]): A =
29+
transparent inline def apply[A](inline pf: PartialFunction[Any,A])(using mc:CpsMonadContext[F]): A =
3030
${
31-
SelectMacro.onceImpl[F,A]('pf, 'api )
31+
SelectMacro.onceImpl[F,A]('pf, 'api, 'mc )
3232
}
3333

3434
/**
@@ -68,7 +68,8 @@ class Select[F[_]](api: Gopher[F]):
6868
}
6969

7070
transparent inline def afold[S](s0:S)(inline step: S => S | SelectFold.Done[S]) : F[S] =
71-
async[F](using api.asyncMonad).apply{
71+
given CpsAsyncMonad[F] = api.asyncMonad
72+
async[F]{
7273
fold(s0)(step)
7374
}
7475

shared/src/main/scala/gopher/SelectForever.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ import scala.concurrent.duration._
1212
class SelectForever[F[_]](api: Gopher[F]) extends SelectGroupBuilder[F,Unit, Unit](api):
1313

1414

15-
transparent inline def apply(inline pf: PartialFunction[Any,Unit]): Unit =
15+
transparent inline def apply(inline pf: PartialFunction[Any,Unit])(using mc:CpsMonadContext[F]): Unit =
1616
${
17-
SelectMacro.foreverImpl('pf,'api)
17+
SelectMacro.foreverImpl('pf,'api, 'mc)
1818
}
1919

2020

shared/src/main/scala/gopher/SelectGroup.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,14 @@ class SelectGroup[F[_], S](api: Gopher[F]) extends SelectListeners[F,S,S]:
7373
def runAsync():F[S] =
7474
retval
7575

76-
transparent inline def apply(inline pf: PartialFunction[Any,S]): S =
76+
transparent inline def apply(inline pf: PartialFunction[Any,S])(using mc: CpsMonadContext[F]): S =
7777
${
78-
SelectMacro.onceImpl[F,S]('pf, 'api )
78+
SelectMacro.onceImpl[F,S]('pf, 'api, 'mc )
7979
}
8080

81-
transparent inline def< 10000 /span> select(inline pf: PartialFunction[Any,S]): S =
81+
transparent inline def select(inline pf: PartialFunction[Any,S])(using mc: CpsMonadContext[F]): S =
8282
${
83-
SelectMacro.onceImpl[F,S]('pf, 'api )
83+
SelectMacro.onceImpl[F,S]('pf, 'api, 'mc )
8484
}
8585

8686
/**

shared/src/main/scala/gopher/SelectListeners.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ trait SelectListeners[F[_],S, R]:
1616

1717
def runAsync():F[R]
1818

19-
transparent inline def run(): R = await(runAsync())(using asyncMonad)
19+
transparent inline def run()(using CpsMonadContext[F]): R = await(runAsync())(using asyncMonad)
2020

2121

2222

shared/src/main/scala/gopher/SelectLoop.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ import java.util.logging.{Level => LogLevel}
1111
class SelectLoop[F[_]](api: Gopher[F]) extends SelectGroupBuilder[F,Boolean, Unit](api):
1212

1313

14-
transparent inline def apply(inline pf: PartialFunction[Any,Boolean]): Unit =
14+
transparent inline def apply(inline pf: PartialFunction[Any,Boolean])(using mc: CpsMonadContext[F]): Unit =
1515
${
16-
SelectMacro.loopImpl[F]('pf, 'api )
16+
SelectMacro.loopImpl[F]('pf, 'api, 'mc )
1717
}
1818

1919
def runAsync(): F[Unit] =

shared/src/main/scala/gopher/SelectMacro.scala

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,12 @@ object SelectMacro:
5151
def buildSelectListenerRun[F[_]:Type, S:Type, R:Type, L <: SelectListeners[F,S,R]:Type](
5252
constructor: Expr[L],
5353
caseDefs: List[SelectorCaseExpr[F,S,R]],
54-
api:Expr[Gopher[F]])(using Quotes): Expr[R] =
54+
api:Expr[Gopher[F]],
55+
monadContext: Expr[CpsMonadContext[F]],
56+
)(using Quotes): Expr[R] =
5557
val g = selectListenerBuilder(constructor, caseDefs)
5658
// dotty bug if g.run
57-
val r = '{ await($g.runAsync())(using ${api}.asyncMonad) }
59+
val r = '{ await($g.runAsync())(using ${api}.asyncMonad, $monadContext) }
5860
r.asExprOf[R]
5961

6062
def buildSelectListenerRunAsync[F[_]:Type, S:Type, R:Type, L <: SelectListeners[F,S,R]:Type](
@@ -68,31 +70,31 @@ object SelectMacro:
6870

6971

7072

71-
def onceImpl[F[_]:Type, A:Type](pf: Expr[PartialFunction[Any,A]], api: Expr[Gopher[F]])(using Quotes): Expr[A] =
73+
def onceImpl[F[_]:Type, A:Type](pf: Expr[PartialFunction[Any,A]], api: Expr[Gopher[F]], monadContext: Expr[CpsMonadContext[F]])(using Quotes): Expr[A] =
7274
def builder(caseDefs: List[SelectorCaseExpr[F,A,A]]):Expr[A] = {
7375
val s0 = '{
7476
new SelectGroup[F,A]($api)
7577
}
76-
buildSelectListenerRun(s0, caseDefs, api)
78+
buildSelectListenerRun(s0, caseDefs, api, monadContext)
7779
}
7880
runImpl(builder, pf)
7981

80-
def loopImpl[F[_]:Type](pf: Expr[PartialFunction[Any,Boolean]], api: Expr[Gopher[F]])(using Quotes): Expr[Unit] =
82+
def loopImpl[F[_]:Type](pf: Expr[PartialFunction[Any,Boolean]], api: Expr[Gopher[F]], monadContext: Expr[CpsMonadContext[F]])(using Quotes): Expr[Unit] =
8183
def builder(caseDefs: List[SelectorCaseExpr[F,Boolean,Unit]]):Expr[Unit] = {
8284
val s0 = '{
8385
new SelectLoop[F]($api)
8486
}
85-
buildSelectListenerRun(s0, caseDefs, api)
87+
buildSelectListenerRun(s0, caseDefs, api, monadContext)
8688
}
8789
runImpl( builder, pf)
8890

8991

90-
def foreverImpl[F[_]:Type](pf: Expr[PartialFunction[Any,Unit]], api:Expr[Gopher[F]])(using Quotes): Expr[Unit] =
92+
def foreverImpl[F[_]:Type](pf: Expr[PartialFunction[Any,Unit]], api:Expr[Gopher[F]], monadContext: Expr[CpsMonadContext[F]])(using Quotes): Expr[Unit] =
9193
def builder(caseDefs: List[SelectorCaseExpr[F,Unit,Unit]]):Expr[Unit] = {
9294
val s0 = '{
9395
new SelectForever[F]($api)
9496
}
95-
buildSelectListenerRun(s0, caseDefs, api)
97+
buildSelectListenerRun(s0, caseDefs, api, monadContext)
9698
}
9799
runImpl(builder, pf)
98100

shared/src/main/scala/gopher/Time.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ abstract class Time[F[_]](gopherAPI: Gopher[F]) {
6060
/**
6161
* synonim for `await(asleep(duration))`. Should be used inside async block.
6262
**/
63-
transparent inline def sleep(duration: FiniteDuration): FiniteDuration =
63+
transparent inline def sleep(duration: FiniteDuration)(using CpsMonadContext[F]): FiniteDuration =
6464
given CpsSchedulingMonad[F] = gopherAPI.asyncMonad
6565
await(asleep(duration))
6666

@@ -156,7 +156,7 @@ object Time:
156156
def asleep[F[_]](duration: FiniteDuration)(using Gopher[F]): F[FiniteDuration] =
157157
summon[Gopher[F]].time.asleep(duration)
158158

159-
transparent inline def sleep[F[_]](duration: FiniteDuration)(using Gopher[F]): FiniteDuration =
159+
transparent inline def sleep[F[_]](duration: FiniteDuration)(using Gopher[F], CpsMonadContext[F]): FiniteDuration =
160160
summon[Gopher[F]].time.sleep(duration)
161161

162162

shared/src/main/scala/gopher/WriteChannel.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@ trait WriteChannel[F[_], A]:
2323
// inline def apply(a:A): Unit = await(awrite(a))(using asyncMonad)
2424
// inline def unapply(a:A): Some[A] = ???
2525

26-
transparent inline def write(inline a:A): Unit = await(awrite(a))(using asyncMonad)
26+
transparent inline def write(inline a:A)(using CpsMonadContext[F]): Unit = await(awrite(a))(using asyncMonad)
2727

2828
@targetName("write1")
29-
transparent inline def <~ (inline a:A): Unit = await(awrite(a))(using asyncMonad)
29+
transparent inline def <~ (inline a:A)(using CpsMonadContext[F]): Unit = await(awrite(a))(using asyncMonad)
3030

3131
@targetName("write2")
32-
transparent inline def ! (inline a:A): Unit = await(awrite(a))(using asyncMonad)
32+
transparent inline def ! (inline a:A)(using CpsMonadContext[F]): Unit = await(awrite(a))(using asyncMonad)
3333

3434

3535
//def Write(x:A):WritePattern = new WritePattern(x)
@@ -51,8 +51,8 @@ trait WriteChannel[F[_], A]:
5151
}
5252
}
5353

54-
transparent inline def writeAll(inline collection: IterableOnce[A]): Unit =
55-
await(awriteAll(collection))(using asyncMonad)
54+
transparent inline def writeAll(inline collection: IterableOnce[A])(using mc: CpsMonadContext[F]): Unit =
55+
await(awriteAll(collection))(using asyncMonad, mc)
5656

5757

5858
def withWriteExpiration(ttl: FiniteDuration, throwTimeouts: Boolean)(using gopherApi: Gopher[F]): WriteChannelWithExpiration[F,A] =

shared/src/main/scala/gopher/monads/ReadChannelCpsMonad.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ import cps._
66
import gopher.impl._
77

88

9-
given ReadChannelCpsMonad[F[_]](using Gopher[F]): CpsMonad[ [A] =>> ReadChannel[F,A]] with
9+
given ReadChannelCpsMonad[F[_]](using Gopher[F]): CpsMonad[[A] =>> ReadChannel[F,A]] with CpsMonadInstanceContext[[A] =>> ReadChannel[F,A]] with
10+
1011

1112
def pure[T](t:T): ReadChannel[F,T] =
1213
ReadChannel.fromValues[F,T](t)

shared/src/main/scala/gopher/monads/ReadTryChannelCpsMonad.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import cps._
77
import gopher.impl._
88

99

10-
given ReadTryChannelCpsMonad[F[_]](using Gopher[F]): CpsAsyncMonad[ [A] =>> ReadChannel[F,Try[A]] ] with
10+
given ReadTryChannelCpsMonad[F[_]](using Gopher[F]): CpsAsyncMonad[[A] =>> ReadChannel[F,Try[A]]] with CpsMonadInstanceContext[[A] =>> ReadChannel[F,Try[A]]] with
1111

1212
type FW[T] = [A] =>> ReadChannel[F,Try[A]]
1313

shared/src/test/scala/examples/SieveSuite.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ object Sieve
4848

4949
def filter1(in:Channel[Future,Int,Int]):ReadChannel[Future,Int] =
5050
{
51+
//implicit val printCode = cps.macros.flags.PrintCode
5152
val q = makeChannel[Int]()
5253
val filtered = makeChannel[Int]()
5354
select.afold(in){ ch =>

0 commit comments

Comments
 (0)
0