-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #96 from VirtusLab/zquery-instance
zio-query instance
- Loading branch information
Showing
7 changed files
with
137 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.13.2") | ||
addSbtPlugin("org.scala-native" % "sbt-scala-native" % "0.4.12") | ||
addSbtPlugin("com.eed3si9n" % "sbt-projectmatrix" % "0.9.0") | ||
addSbtPlugin("com.github.sbt" % "sbt-ci-release" % "1.5.11") | ||
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.16.0") | ||
addSbtPlugin("org.scala-native" % "sbt-scala-native" % "0.4.17") | ||
addSbtPlugin("com.eed3si9n" % "sbt-projectmatrix" % "0.10.0") | ||
addSbtPlugin("com.github.sbt" % "sbt-ci-release" % "1.5.12") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package avocado.instances | ||
|
||
import avocado.AvocADO | ||
import zio.query.ZQuery | ||
|
||
object zioquery { | ||
given [E, R]: AvocADO[[X] =>> ZQuery[R, E, X]] = new AvocADO[[X] =>> ZQuery[R, E, X]] { | ||
def pure[A](a: A): ZQuery[R, E, A] = ZQuery.succeed(a) | ||
def map[A, B](fa: ZQuery[R, E, A], f: A => B): ZQuery[R, E, B] = fa.map(f) | ||
def zip[A, B](fa: ZQuery[R, E, A], fb: ZQuery[R, E, B]): ZQuery[R, E, (A, B)] = fa.zipPar(fb) | ||
def flatMap[A, B](fa: ZQuery[R, E, A], f: A => ZQuery[R, E, B]): ZQuery[R, E, B] = fa.flatMap(f) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package avocado.tests | ||
|
||
import zio.* | ||
import zio.query.* | ||
|
||
abstract class BaseZQueryTest extends munit.FunSuite { | ||
|
||
def testWithTimeLimit[R, E, A](name: String, maxMillis: Long)(body: ZQuery[R, E, A])(expected: Either[E, A]): Unit = { | ||
test(name) { | ||
val start = java.lang.System.currentTimeMillis() | ||
val res: Either[E, A] = Unsafe.unsafe { unsafe ?=> | ||
zio.Runtime.default.unsafe.run( | ||
body.either.run.asInstanceOf[ZIO[Any, Any, Either[E, A]]] | ||
).getOrThrowFiberFailure() | ||
} | ||
val end = java.lang.System.currentTimeMillis() | ||
assertEquals(res, expected) | ||
assert(end - start < maxMillis) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package avocado.tests | ||
|
||
import avocado.* | ||
import avocado.instances.zioquery.given | ||
import scala.concurrent.duration.* | ||
import zio.* | ||
import zio.query.ZQuery | ||
|
||
class ZQueryTests extends BaseZQueryTest { | ||
|
||
testWithTimeLimit("ZQuery comprehension 1", 4000) { | ||
val wait = ZQuery.fromZIO(ZIO.sleep(1000.millis)) | ||
ado { | ||
for { | ||
a <- wait.map(_ => 1) | ||
} yield a | ||
} | ||
}(Right(1)) | ||
|
||
testWithTimeLimit("ZQuery comprehension 2", 900) { | ||
val wait = ZQuery.fromZIO(ZIO.sleep(500.millis)) | ||
ado { | ||
for { | ||
a <- wait.map(_ => 1) | ||
b <- wait.map(_ => 2) | ||
} yield a + b | ||
} | ||
}(Right(3)) | ||
|
||
testWithTimeLimit("ZQuery comprehension 3", 1400) { | ||
val wait = ZQuery.fromZIO(ZIO.sleep(500.millis)) | ||
ado { | ||
for { | ||
a <- wait.map(_ => 1) | ||
b <- wait.map(_ => 2) | ||
c <- ZQuery.fromZIO(ZIO.succeed(a + b)) | ||
d <- wait.map(_ => 4) | ||
} yield c + d | ||
} | ||
}(Right(7)) | ||
|
||
testWithTimeLimit("ZQuery comprehension 4", 1400) { | ||
val wait = ZQuery.fromZIO(ZIO.sleep(500.millis)) | ||
ado { | ||
for { | ||
a <- wait.map(_ => 1) | ||
b <- wait.map(_ => 2) | ||
c <- ZQuery.fromZIO(ZIO.succeed(a + b)) | ||
d <- wait.map(_ => 4) | ||
e <- wait.map(Function.const(5)) | ||
} yield c + d | ||
} | ||
}(Right(7)) | ||
|
||
testWithTimeLimit("ZQuery comprehension 5", 1400) { | ||
val wait = ZQuery.fromZIO(ZIO.sleep(500.millis)) | ||
ado { | ||
for { | ||
a <- wait.map(_ => 1) | ||
b <- wait.map(_ => 2) | ||
c <- ZQuery.fromZIO(ZIO.succeed(a + b)) | ||
d <- wait.map(_ => 4) | ||
e <- wait.map(Function.const(5)) | ||
} yield c + d | ||
} | ||
}(Right(7)) | ||
|
||
} |