Skip to content

Commit

Permalink
3.0.0-M3
Browse files Browse the repository at this point in the history
  • Loading branch information
tpolecat committed Jan 5, 2021
1 parent 27a3811 commit f044d3c
Show file tree
Hide file tree
Showing 15 changed files with 222 additions and 15 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,7 @@ bin/
metals.sbt

# VS-Code
.vscode/
.vscode/

# sbt
.bsp/
18 changes: 9 additions & 9 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import sbt.dsl.LinterLevel.Ignore
lazy val catsVersion = "2.3.1"
lazy val catsEffectVersion = "2.3.1"
lazy val circeVersion = "0.13.0"
lazy val collCompatVersion = "2.3.1"
lazy val fs2Version = "2.5.0-M2"
lazy val fs2Version = "2.5.0"
lazy val h2Version = "1.4.200"
lazy val hikariVersion = "3.4.5"
lazy val kindProjectorVersion = "0.11.2"
Expand All @@ -22,7 +21,8 @@ lazy val silencerVersion = "1.7.1"
lazy val specs2Version = "4.10.5"
lazy val scala212Version = "2.12.12"
lazy val scala213Version = "2.13.4"
lazy val scala30Version = "3.0.0-M2"
lazy val scala30VersionOld = "3.0.0-M2"
lazy val scala30Version = "3.0.0-M3"
lazy val slf4jVersion = "1.7.30"

// These are releases to ignore during MiMa checks
Expand All @@ -42,7 +42,7 @@ lazy val compilerFlags = Seq(
"-Xfatal-warnings"
),
libraryDependencies ++= Seq(
"org.scala-lang.modules" %% "scala-collection-compat" % collCompatVersion
"org.scala-lang.modules" %% "scala-collection-compat" % (if (scalaVersion.value == "3.0.0-M2") "2.3.1" else "2.3.2")
)
)

Expand All @@ -55,7 +55,7 @@ lazy val commonSettings =
compilerFlags ++
Seq(
scalaVersion := scala213Version,
crossScalaVersions := Seq(scala212Version, scala213Version, scala30Version),
crossScalaVersions := Seq(scala212Version, scala213Version, scala30VersionOld, scala30Version),

// These sbt-header settings can't be set in ThisBuild for some reason
headerMappings := headerMappings.value + (HeaderFileType.scala -> HeaderCommentStyle.cppStyleLineComment),
Expand All @@ -80,8 +80,8 @@ lazy val commonSettings =

// MUnit
libraryDependencies ++= Seq(
"org.typelevel" %% "scalacheck-effect-munit" % "0.6.0" % Test,
"org.typelevel" %% "munit-cats-effect-2" % "0.11.0" % Test,
"org.typelevel" %% "scalacheck-effect-munit" % "0.7.0" % Test,
"org.typelevel" %% "munit-cats-effect-2" % "0.12.0" % Test,
),
testFrameworks += new TestFramework("munit.Framework"),

Expand Down Expand Up @@ -220,7 +220,7 @@ lazy val core = project
libraryDependencies ++= Seq(
"com.chuusai" %% "shapeless" % shapelessVersion,
).filterNot(_ => isDotty.value) ++ Seq(
"org.tpolecat" %% "typename" % "0.1.2",
"org.tpolecat" %% "typename" % "0.1.3",
"com.h2database" % "h2" % h2Version % "test",
),
scalacOptions += "-Yno-predef",
Expand Down Expand Up @@ -460,7 +460,7 @@ lazy val refined = project
name := "doobie-refined",
description := "Refined support for doobie.",
libraryDependencies ++= Seq(
"eu.timepit" %% "refined" % refinedVersion,
"eu.timepit" %% "refined" % (if (scalaVersion.value == "3.0.0-M2") "0.9.19" else "0.9.20"),
"com.h2database" % "h2" % h2Version % "test"
)
)
Expand Down
17 changes: 17 additions & 0 deletions modules/core/src/main/scala-3.0.0-M3/util/GetPlatform.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright (c) 2013-2020 Rob Norris and Contributors
// This software is licensed under the MIT License (MIT).
// For more information see LICENSE or https://opensource.org/licenses/MIT

package doobie.util

import scala.deriving.Mirror

trait GetPlatform:

// Get is available for single-element products.
given x[P <: Product, A](
using p: Mirror.ProductOf[P],
i: p.MirroredElemTypes =:= (A *: EmptyTuple),
g: Get[A],
): Get[P] =
g.map(a => p.fromProduct(a *: EmptyTuple))
17 changes: 17 additions & 0 deletions modules/core/src/main/scala-3.0.0-M3/util/PutPlatform.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright (c) 2013-2020 Rob Norris and Contributors
// This software is licensed under the MIT License (MIT).
// For more information see LICENSE or https://opensource.org/licenses/MIT

package doobie.util

import scala.deriving.Mirror

trait PutPlatform:

// Put is available for single-element products.
given [P <: Product, A](
using m: Mirror.ProductOf[P],
i: m.MirroredElemTypes =:= (A *: EmptyTuple),
p: Put[A]
): Put[P] =
p.contramap(p => i(Tuple.fromProductTyped(p)).head)
64 changes: 64 additions & 0 deletions modules/core/src/main/scala-3.0.0-M3/util/ReadPlatform.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// Copyright (c) 2013-2020 Rob Norris and Contributors
// This software is licensed under the MIT License (MIT).
// For more information see LICENSE or https://opensource.org/licenses/MIT

package doobie.util

import scala.deriving.Mirror

trait ReadPlatform:

// Trivial Read for EmptyTuple
given Read[EmptyTuple] =
new Read[EmptyTuple](Nil, (_, _) => EmptyTuple)

// Read for head and tail.
given [H, T <: Tuple](using H: => Read[H], T: => Read[T]): Read[H *: T] =
new Read[H *: T](
H.gets ++ T.gets,
(rs, n) => H.unsafeGet(rs, n) *: T.unsafeGet(rs, n + H.length)
)

// Generic Read for products.
given [P <: Product, A](
using m: Mirror.ProductOf[P],
i: A =:= m.MirroredElemTypes,
w: Read[A]
): Read[P] =
w.map(a => m.fromProduct(i(a)))

given roe: Read[Option[EmptyTuple]] =
new Read[Option[EmptyTuple]](Nil, (_, _) => Some(EmptyTuple))

given rou: Read[Option[Unit]] =
new Read[Option[Unit]](Nil, (_, _) => Some(()))

given cons1[H, T <: Tuple](
using H: => Read[Option[H]],
T: => Read[Option[T]],
): Read[Option[H *: T]] =
new Read[Option[H *: T]](
H.gets ++ T.gets,
(rs, n) =>
for {
h <- H.unsafeGet(rs, n)
t <- T.unsafeGet(rs, n + H.length)
} yield h *: t
)

given cons2[H, T <: Tuple](
using H: => Read[Option[H]],
T: => Read[Option[T]]
): Read[Option[Option[H] *: T]] =
new Read[Option[Option[H] *: T]](
H.gets ++ T.gets,
(rs, n) => T.unsafeGet(rs, n + H.length).map(H.unsafeGet(rs, n) *: _)
)

// Generic Read for option of products.
given [P <: Product, A](
using m: Mirror.ProductOf[P],
i: A =:= m.MirroredElemTypes,
w: Read[Option[A]]
): Read[Option[P]] =
w.map(a => a.map(a => m.fromProduct(i(a))))
79 changes: 79 additions & 0 deletions modules/core/src/main/scala-3.0.0-M3/util/WritePlatform.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
// Copyright (c) 2013-2020 Rob Norris and Contributors
// This software is licensed under the MIT License (MIT).
// For more information see LICENSE or https://opensource.org/licenses/MIT

package doobie.util

import scala.deriving.Mirror

trait WritePlatform:

// Trivial write for empty tuple.
given Write[EmptyTuple] =
new Write(Nil, _ => Nil, (_, _, _) => (),(_, _, _) => ())

// Inductive write for writable head and tail.
given [H, T <: Tuple](using H: => Write[H], T: => Write[T]): Write[H *: T] =
new Write(
H.puts ++ T.puts,
{ case h *: t => H.toList(h) ++ T.toList(t) },
{ case (ps, n, h *: t) => H.unsafeSet(ps, n, h); T.unsafeSet(ps, n + H.length, t) },
{ case (rs, n, h *: t) => H.unsafeUpdate(rs, n, h); T.unsafeUpdate(rs, n + H.length, t) }
)

// Generic write for products.
given [P <: Product, A](
using m: Mirror.ProductOf[P],
i: m.MirroredElemTypes =:= A,
w: Write[A]
): Write[P] =
w.contramap(p => i(Tuple.fromProductTyped(p)))

// Trivial write for option of empty tuple.
given woe: Write[Option[EmptyTuple]] =
new Write[Option[EmptyTuple]](Nil, _ => Nil, (_, _, _) => (), (_, _, _) => ())

// Trivial write for option of Unit.
given wou: Write[Option[Unit]] =
new Write[Option[Unit]](Nil, _ => Nil, (_, _, _) => (), (_, _, _) => ())

// Write[Option[H]], Write[Option[T]] implies Write[Option[H *: T]]
given cons1[H, T <: Tuple](
using H: => Write[Option[H]],
T: => Write[Option[T]],
// N: H <:!< Option[_],
): Write[Option[H *: T]] =

def split[A](i: Option[H *: T])(f: (Option[H], Option[T]) => A): A =
i.fold(f(None, None)) { case h *: t => f(Some(h), Some(t)) }

new Write(
H.puts ++ T.puts,
split(_) { (h, t) => H.toList(h) ++ T.toList(t) },
(ps, n, i) => split(i) { (h, t) => H.unsafeSet(ps, n, h); T.unsafeSet(ps, n + H.length, t) },
(rs, n, i) => split(i) { (h, t) => H.unsafeUpdate(rs, n, h); T.unsafeUpdate(rs, n + H.length, t) }
)

// Write[Option[H]], Write[Option[T]] implies Write[Option[Option[H] *: T]]
given cons2[H, T <: Tuple](
using H: => Write[Option[H]],
T: => Write[Option[T]]
): Write[Option[Option[H] *: T]] =

def split[A](i: Option[Option[H] *: T])(f: (Option[H], Option[T]) => A): A =
i.fold(f(None, None)) { case oh *: t => f(oh, Some(t)) }

new Write(
H.puts ++ T.puts,
split(_) { (h, t) => H.toList(h) ++ T.toList(t) },
(ps, n, i) => split(i) { (h, t) => H.unsafeSet(ps, n, h); T.unsafeSet(ps, n + H.length, t) },
(rs, n, i) => split(i) { (h, t) => H.unsafeUpdate(rs, n, h); T.unsafeUpdate(rs, n + H.length, t) }
)

// Generic write for options of products.
given [P <: Product, A](
using m: Mirror.ProductOf[P],
i: m.MirroredElemTypes =:= A,
w: Write[Option[A]]
): Write[Option[P]] =
w.contramap(op => op.map(p => i(Tuple.fromProductTyped(p))))
2 changes: 1 addition & 1 deletion modules/example/src/main/scala/example/Join.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ object Join {
LEFT OUTER JOIN city c
ON k.code = c.countrycode AND c.name like $filter
""".query[(Country, Option[Int], Option[String])]
.map { case (k, a, b) => (k, (a, b).mapN(City)) }
.map { case (k, a, b) => (k, (a, b).mapN(City(_, _))) }

// New style (better)
def countriesAndCities2(filter: String): Query0[(Country, Option[City])] =
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright (c) 2013-2020 Rob Norris and Contributors
// This software is licensed under the MIT License (MIT).
// For more information see LICENSE or https://opensource.org/licenses/MIT

package doobie.postgres

import scala.deriving.Mirror

trait TextPlatform { this: Text.type =>

// EmptyTuple isn't a valid Text but a single-element Tuple is
given [A](using csv: Text[A]): Text[A *: EmptyTuple] =
csv.contramap(_.head)

// Tuples of more that one element
given [H, T <: Tuple](using h: Text[H], t: Text[T]): Text[H *: T] =
(h product t).contramap(l => (l.head, l.tail))

// Put is available for single-element products.
given [P <: Product, A](
using m: Mirror.ProductOf[P],
i: m.MirroredElemTypes =:= A,
t: Text[A]
): Text[P] =
t.contramap(p => i(Tuple.fromProductTyped(p)))

}
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version=1.3.9
sbt.version=1.4.6
6 changes: 3 additions & 3 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
addSbtPlugin("com.lightbend.paradox" % "sbt-paradox" % "0.8.0")
addSbtPlugin("com.lightbend.paradox" % "sbt-paradox" % "0.9.1")
addSbtPlugin("com.typesafe.sbt" % "sbt-site" % "1.4.1")
addSbtPlugin("com.typesafe.sbt" % "sbt-ghpages" % "0.6.3")
addSbtPlugin("com.geirsson" % "sbt-ci-release" % "1.5.5")
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "1.6.1")
addSbtPlugin("com.timushev.sbt" % "sbt-updates" % "0.5.1")
addSbtPlugin("pl.project13.scala" % "sbt-jmh" % "0.3.7")
addSbtPlugin("pl.project13.scala" % "sbt-jmh" % "0.4.0")
addSbtPlugin("de.heikoseeberger" % "sbt-header" % "5.6.0")
addSbtPlugin("io.chrisdavenport" % "sbt-mima-version-check" % "0.1.2")
addSbtPlugin("io.github.davidgregory084" % "sbt-tpolecat" % "0.1.16")
addSbtPlugin("org.scalameta" % "sbt-mdoc" % "2.2.14")
addSbtPlugin("ch.epfl.lamp" % "sbt-dotty" % "0.4.6")
addSbtPlugin("ch.epfl.lamp" % "sbt-dotty" % "0.5.1")

0 comments on commit f044d3c

Please sign in to comment.