Skip to content

Commit

Permalink
Implement BlockedRequests#fold (#380)
Browse files Browse the repository at this point in the history
* implement blockedrequests#fold

* format

* fix scala 3 issue

* update dependencies
  • Loading branch information
adamgfraser authored Nov 15, 2022
1 parent a9b4294 commit b459def
Show file tree
Hide file tree
Showing 18 changed files with 284 additions and 212 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ jobs:
fail-fast: false
matrix:
java: ['[email protected]', '[email protected]']
scala: ['2.11.12', '2.12.14', '2.13.6', '3.1.0']
scala: ['2.11.12', '2.12.17', '2.13.10', '3.2.1']
steps:
- name: Checkout current branch
uses: actions/[email protected]
Expand Down
17 changes: 11 additions & 6 deletions .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
version = "2.7.5"
version = "3.6.1"
maxColumn = 120
align.preset = most
align.multiline = false
continuationIndent.defnSite = 2
assumeStandardLibraryStripMargin = true
docstrings = JavaDoc
docstrings.style = Asterisk
docstrings.wrapMaxColumn = 80
lineEndings = preserve
includeCurlyBraceInSelectChains = false
danglingParentheses.preset = true
spaces {
inImportCurlyBraces = true
}
optIn.annotationNewlines = true
newlines.alwaysBeforeMultilineDef = false
runner.dialect = scala213
rewrite.rules = [RedundantBraces]

rewrite.rules = [SortImports, RedundantBraces]
rewrite.redundantBraces.generalExpressions = false
rewriteTokens = {
"⇒": "=>"
"→": "->"
"←": "<-"
}
12 changes: 6 additions & 6 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ name := "zio-query"
inThisBuild(
List(
organization := "dev.zio",
homepage := Some(url("https://zio.github.io/zio-query/")),
licenses := List("Apache-2.0" -> url("http://www.apache.org/licenses/LICENSE-2.0")),
homepage := Some(url("https://zio.github.io/zio-query/")),
licenses := List("Apache-2.0" -> url("http://www.apache.org/licenses/LICENSE-2.0")),
developers := List(
Developer(
"adamgfraser",
Expand All @@ -23,7 +23,7 @@ inThisBuild(
addCommandAlias("fmt", "all scalafmtSbt scalafmt test:scalafmt")
addCommandAlias("check", "all scalafmtSbtCheck scalafmtCheck test:scalafmtCheck")

val zioVersion = "2.0.0"
val zioVersion = "2.0.3"

lazy val root = project
.in(file("."))
Expand Down Expand Up @@ -69,16 +69,16 @@ lazy val docs = project
.in(file("zio-query-docs"))
.settings(
publish / skip := true,
moduleName := "zio-query-docs",
moduleName := "zio-query-docs",
scalacOptions -= "-Yno-imports",
scalacOptions -= "-Xfatal-warnings",
libraryDependencies ++= Seq(
"dev.zio" %% "zio" % zioVersion
),
ScalaUnidoc / unidoc / unidocProjectFilter := inProjects(root),
ScalaUnidoc / unidoc / target := (LocalRootProject / baseDirectory).value / "website" / "static" / "api",
ScalaUnidoc / unidoc / target := (LocalRootProject / baseDirectory).value / "website" / "static" / "api",
cleanFiles += (ScalaUnidoc / unidoc / target).value,
docusaurusCreateSite := docusaurusCreateSite.dependsOn(Compile / unidoc).value,
docusaurusCreateSite := docusaurusCreateSite.dependsOn(Compile / unidoc).value,
docusaurusPublishGhpages := docusaurusPublishGhpages.dependsOn(Compile / unidoc).value
)
.dependsOn(zioQueryJVM)
Expand Down
24 changes: 12 additions & 12 deletions project/BuildHelper.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import scalafix.sbt.ScalafixPlugin.autoImport.scalafixSemanticdb
object BuildHelper {

private val versions: Map[String, String] = {
import org.snakeyaml.engine.v2.api.{ Load, LoadSettings }
import org.snakeyaml.engine.v2.api.{Load, LoadSettings}

import java.util.{ List => JList, Map => JMap }
import java.util.{List => JList, Map => JMap}
import scala.jdk.CollectionConverters._

val doc = new Load(LoadSettings.builder().build())
Expand All @@ -25,13 +25,13 @@ object BuildHelper {
val Scala211: String = versions("2.11")
val Scala212: String = versions("2.12")
val Scala213: String = versions("2.13")
val ScalaDotty: String = versions("3.1")
val ScalaDotty: String = versions("3.2")

def buildInfoSettings(packageName: String) =
Seq(
buildInfoKeys := Seq[BuildInfoKey](name, version, scalaVersion, sbtVersion, isSnapshot),
buildInfoKeys := Seq[BuildInfoKey](name, version, scalaVersion, sbtVersion, isSnapshot),
buildInfoPackage := packageName,
buildInfoObject := "BuildInfo"
buildInfoObject := "BuildInfo"
)

private val stdOptions = Seq(
Expand Down Expand Up @@ -182,18 +182,18 @@ object BuildHelper {
)

def stdSettings(prjName: String) = Seq(
name := s"$prjName",
scalacOptions := stdOptions,
crossScalaVersions := Seq(Scala213, Scala212, Scala211),
name := s"$prjName",
scalacOptions := stdOptions,
crossScalaVersions := Seq(Scala213, Scala212, Scala211),
ThisBuild / scalaVersion := crossScalaVersions.value.head,
scalacOptions := stdOptions ++ extraOptions(scalaVersion.value, optimize = !isSnapshot.value),
scalacOptions := stdOptions ++ extraOptions(scalaVersion.value, optimize = !isSnapshot.value),
libraryDependencies ++= {
if (scalaVersion.value == ScalaDotty)
Seq("com.github.ghik" % s"silencer-lib_$Scala213" % "1.7.5" % Provided)
Seq("com.github.ghik" % s"silencer-lib_$Scala213" % "1.7.12" % Provided)
else
Seq(
"com.github.ghik" % "silencer-lib" % "1.7.7" % Provided cross CrossVersion.full,
compilerPlugin("com.github.ghik" % "silencer-plugin" % "1.7.7" cross CrossVersion.full),
"com.github.ghik" % "silencer-lib" % "1.7.12" % Provided cross CrossVersion.full,
compilerPlugin("com.github.ghik" % "silencer-plugin" % "1.7.12" cross CrossVersion.full),
compilerPlugin(scalafixSemanticdb)
)
},
Expand Down
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version = 1.5.5
sbt.version = 1.8.0
24 changes: 12 additions & 12 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.7.1")
addSbtPlugin("org.portable-scala" % "sbt-scalajs-crossproject" % "1.1.0")
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.4.3")
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.11.0")
addSbtPlugin("org.portable-scala" % "sbt-scalajs-crossproject" % "1.2.0")
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.4.6")
addSbtPlugin("pl.project13.scala" % "sbt-jmh" % "0.4.3")
addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.10.0")
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "1.9.2")
addSbtPlugin("org.scalameta" % "sbt-mdoc" % "2.2.23")
addSbtPlugin("ch.epfl.scala" % "sbt-bloop" % "1.4.11")
addSbtPlugin("com.eed3si9n" % "sbt-unidoc" % "0.4.3")
addSbtPlugin("com.geirsson" % "sbt-ci-release" % "1.5.7")
addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.11.0")
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "2.0.6")
addSbtPlugin("org.scalameta" % "sbt-mdoc" % "2.3.2")
addSbtPlugin("ch.epfl.scala" % "sbt-bloop" % "1.5.4")
addSbtPlugin("com.github.sbt" % "sbt-unidoc" % "0.5.0")
addSbtPlugin("com.github.sbt" % "sbt-ci-release" % "1.5.10")
addSbtPlugin("com.github.cb372" % "sbt-explicit-dependencies" % "0.2.16")
addSbtPlugin("com.thoughtworks.sbt-api-mappings" % "sbt-api-mappings" % "3.0.0")
addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.9.31")
addSbtPlugin("com.thoughtworks.sbt-api-mappings" % "sbt-api-mappings" % "3.0.2")
addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.10.4")

libraryDependencies += "org.snakeyaml" % "snakeyaml-engine" % "2.3"
libraryDependencies += "org.snakeyaml" % "snakeyaml-engine" % "2.5"
24 changes: 18 additions & 6 deletions sbt
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@

set -o pipefail

declare -r sbt_release_version="1.4.8"
declare -r sbt_unreleased_version="1.5.0-M2"
declare -r sbt_release_version="1.8.0"
declare -r sbt_unreleased_version="1.8.0"

declare -r latest_213="2.13.5"
declare -r latest_212="2.12.12"
declare -r latest_213="2.13.10"
declare -r latest_212="2.12.17"
declare -r latest_211="2.11.12"
declare -r latest_210="2.10.7"
declare -r latest_29="2.9.3"
Expand Down Expand Up @@ -216,7 +216,8 @@ getJavaVersion() {
# but on 9 and 10 it's 9.x.y and 10.x.y.
if [[ "$str" =~ ^1\.([0-9]+)(\..*)?$ ]]; then
echo "${BASH_REMATCH[1]}"
elif [[ "$str" =~ ^([0-9]+)(\..*)?$ ]]; then
# Fixes https://github.com/dwijnand/sbt-extras/issues/326
elif [[ "$str" =~ ^([0-9]+)(\..*)?(-ea)?$ ]]; then
echo "${BASH_REMATCH[1]}"
elif [[ -n "$str" ]]; then
echoerr "Can't parse java version from: $str"
Expand Down Expand Up @@ -252,7 +253,9 @@ is_apple_silicon() { [[ "$(uname -s)" == "Darwin" && "$(uname -m)" == "arm64" ]]
# MaxPermSize critical on pre-8 JVMs but incurs noisy warning on 8+
default_jvm_opts() {
local -r v="$(java_version)"
if [[ $v -ge 10 ]]; then
if [[ $v -ge 17 ]]; then
echo "$default_jvm_opts_common"
elif [[ $v -ge 10 ]]; then
if is_apple_silicon; then
# As of Dec 2020, JVM for Apple Silicon (M1) doesn't support JVMCI
echo "$default_jvm_opts_common"
Expand Down Expand Up @@ -385,10 +388,12 @@ usage() {
set_sbt_version
cat <<EOM
Usage: $script_name [options]
Note that options which are passed along to sbt begin with -- whereas
options to this runner use a single dash. Any sbt command can be scheduled
to run first by prefixing the command with --, so --warn, --error and so on
are not special.
-h | -help print this message
-v verbose operation (this runner is chattier)
-d, -w, -q aliases for --debug, --warn, --error (q means quiet)
Expand All @@ -406,13 +411,15 @@ are not special.
-batch Disable interactive mode
-prompt <expr> Set the sbt prompt; in expr, 's' is the State and 'e' is Extracted
-script <file> Run the specified file as a scala script
# sbt version (default: sbt.version from $buildProps if present, otherwise $sbt_release_version)
-sbt-version <version> use the specified version of sbt (default: $sbt_release_version)
-sbt-force-latest force the use of the latest release of sbt: $sbt_release_version
-sbt-dev use the latest pre-release version of sbt: $sbt_unreleased_version
-sbt-jar <path> use the specified jar as the sbt launcher
-sbt-launch-dir <path> directory to hold sbt launchers (default: $sbt_launch_dir)
-sbt-launch-repo <url> repo url for downloading sbt launcher jar (default: $(url_base "$sbt_version"))
# scala version (default: as chosen by sbt)
-28 use $latest_28
-29 use $latest_29
Expand All @@ -423,8 +430,10 @@ are not special.
-scala-home <path> use the scala build at the specified directory
-scala-version <version> use the specified version of scala
-binary-version <version> use the specified scala version when searching for dependencies
# java version (default: java from PATH, currently $(java -version 2>&1 | grep version))
-java-home <path> alternate JAVA_HOME
# passing options to the jvm - note it does NOT use JAVA_OPTS due to pollution
# The default set is used if JVM_OPTS is unset and no -jvm-opts file is found
<default> $(default_jvm_opts)
Expand All @@ -434,12 +443,14 @@ are not special.
-jvm-opts <path> file containing jvm args (if not given, .jvmopts in project root is used if present)
-Dkey=val pass -Dkey=val directly to the jvm
-J-X pass option -X directly to the jvm (-J is stripped)
# passing options to sbt, OR to this runner
SBT_OPTS environment variable holding either the sbt args directly, or
the reference to a file containing sbt args if given path is prepended by '@' (e.g. '@/etc/sbtopts')
Note: "@"-file is overridden by local '.sbtopts' or '-sbt-opts' argument.
-sbt-opts <path> file containing sbt args (if not given, .sbtopts in project root is used if present)
-S-X add -X to sbt's scalacOptions (-S is stripped)
# passing options exclusively to this runner
SBTX_OPTS environment variable holding either the sbt-extras args directly, or
the reference to a file containing sbt-extras args if given path is prepended by '@' (e.g. '@/etc/sbtxopts')
Expand Down Expand Up @@ -592,6 +603,7 @@ fi
$(pwd) doesn't appear to be an sbt project.
If you want to start sbt anyway, run:
$0 -sbt-create
EOM
exit 1
}
Expand Down
18 changes: 9 additions & 9 deletions zio-query/shared/src/main/scala/zio/query/Cache.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,19 @@ import zio.stacktracer.TracingImplicits.disableAutoTrace
trait Cache {

/**
* Looks up a request in the cache, failing with the unit value if the
* request is not in the cache, succeeding with `Ref(None)` if the request is
* in the cache but has not been executed yet, or `Ref(Some(value))` if the
* request has been executed.
* Looks up a request in the cache, failing with the unit value if the request
* is not in the cache, succeeding with `Ref(None)` if the request is in the
* cache but has not been executed yet, or `Ref(Some(value))` if the request
* has been executed.
*/
def get[E, A](request: Request[E, A])(implicit trace: Trace): IO[Unit, Ref[Option[Either[E, A]]]]

/**
* Looks up a request in the cache. If the request is not in the cache
* returns a `Left` with a `Ref` that can be set with a `Some` to complete
* the request. If the request is in the cache returns a `Right` with a `Ref`
* that either contains `Some` with a result if the request has been executed
* or `None` if the request has not been executed yet.
* Looks up a request in the cache. If the request is not in the cache returns
* a `Left` with a `Ref` that can be set with a `Some` to complete the
* request. If the request is in the cache returns a `Right` with a `Ref` that
* either contains `Some` with a result if the request has been executed or
* `None` if the request has not been executed yet.
*/
def lookup[R, E, A, B](request: A)(implicit
ev: A <:< Request[E, B],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ package zio.query
import zio.stacktracer.TracingImplicits.disableAutoTrace

/**
* A `CompletedRequestMap` is a universally quantified mapping from requests
* of type `Request[E, A]` to results of type `Either[E, A]` for all types `E`
* and `A`. The guarantee is that for any request of type `Request[E, A]`, if
* there is a corresponding value in the map, that value is of type
* `Either[E, A]`. This is used by the library to support data sources that
* return different result types for different requests while guaranteeing that
* results will be of the type requested.
* A `CompletedRequestMap` is a universally quantified mapping from requests of
* type `Request[E, A]` to results of type `Either[E, A]` for all types `E` and
* `A`. The guarantee is that for any request of type `Request[E, A]`, if there
* is a corresponding value in the map, that value is of type `Either[E, A]`.
* This is used by the library to support data sources that return different
* result types for different requests while guaranteeing that results will be
* of the type requested.
*/
final class CompletedRequestMap private (private val map: Map[Any, Either[Any, Any]]) { self =>

Expand Down
Loading

0 comments on commit b459def

Please sign in to comment.