-
Notifications
You must be signed in to change notification settings - Fork 356
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 #2070 from tpolecat/tuple_read_write_instances
Make tuple Read/Write instances available without an import
- Loading branch information
Showing
21 changed files
with
171 additions
and
25 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
File renamed without changes.
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
File renamed without changes.
32 changes: 32 additions & 0 deletions
32
modules/core/src/main/scala-2/doobie/util/ReadPlatform.scala
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,32 @@ | ||
// 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 shapeless.{Generic, HList, IsTuple, Lazy} | ||
|
||
trait ReadPlatform { | ||
|
||
// Derivation for product types (i.e. case class) | ||
implicit def genericTuple[A, Repr <: HList](implicit | ||
gen: Generic.Aux[A, Repr], | ||
G: Lazy[MkRead[Repr]], | ||
isTuple: IsTuple[A] | ||
): MkRead[A] = { | ||
val _ = isTuple | ||
MkRead.generic[A, Repr] | ||
} | ||
|
||
// Derivation for optional of product types (i.e. case class) | ||
implicit def ogenericTuple[A, Repr <: HList]( | ||
implicit | ||
G: Generic.Aux[A, Repr], | ||
B: Lazy[MkRead[Option[Repr]]], | ||
isTuple: IsTuple[A] | ||
): MkRead[Option[A]] = { | ||
val _ = isTuple | ||
MkRead.ogeneric[A, Repr] | ||
} | ||
|
||
} |
30 changes: 30 additions & 0 deletions
30
modules/core/src/main/scala-2/doobie/util/WritePlatform.scala
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,30 @@ | ||
// 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 shapeless.{Generic, HList, IsTuple, Lazy} | ||
|
||
trait WritePlatform { | ||
|
||
implicit def genericTuple[A, Repr]( | ||
implicit | ||
gen: Generic.Aux[A, Repr], | ||
A: Lazy[MkWrite[Repr]], | ||
isTuple: IsTuple[A] | ||
): MkWrite[A] = { | ||
val _ = isTuple | ||
MkWrite.generic[A, Repr] | ||
} | ||
|
||
implicit def ogenericTuple[A, Repr <: HList]( | ||
implicit | ||
G: Generic.Aux[A, Repr], | ||
A: Lazy[MkWrite[Option[Repr]]], | ||
isTuple: IsTuple[A] | ||
): MkWrite[Option[A]] = { | ||
val _ = isTuple | ||
MkWrite.ogeneric[A, Repr] | ||
} | ||
} |
File renamed without changes.
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
File renamed without changes.
26 changes: 26 additions & 0 deletions
26
modules/core/src/main/scala-3/doobie/util/ReadPlatform.scala
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,26 @@ | ||
// 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: | ||
// Generic Read for products. | ||
given derivedTuple[P <: Tuple, A]( | ||
using | ||
m: Mirror.ProductOf[P], | ||
i: A =:= m.MirroredElemTypes, | ||
w: MkRead[A] | ||
): MkRead[P] = | ||
MkRead.derived[P, A] | ||
|
||
// Generic Read for option of products. | ||
given derivedOptionTuple[P <: Tuple, A]( | ||
using | ||
m: Mirror.ProductOf[P], | ||
i: A =:= m.MirroredElemTypes, | ||
w: MkRead[Option[A]] | ||
): MkRead[Option[P]] = | ||
MkRead.derivedOption[P, A] |
27 changes: 27 additions & 0 deletions
27
modules/core/src/main/scala-3/doobie/util/WritePlatform.scala
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,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.util | ||
|
||
import scala.deriving.Mirror | ||
|
||
trait WritePlatform: | ||
|
||
// Derivation for product types (i.e. case class) | ||
given derivedTuple[P <: Tuple, A]( | ||
using | ||
m: Mirror.ProductOf[P], | ||
i: m.MirroredElemTypes =:= A, | ||
w: MkWrite[A] | ||
): MkWrite[P] = | ||
MkWrite.derived[P, A] | ||
|
||
// Derivation for optional product types | ||
given derivedOptionTuple[P <: Tuple, A]( | ||
using | ||
m: Mirror.ProductOf[P], | ||
i: m.MirroredElemTypes =:= A, | ||
w: MkWrite[Option[A]] | ||
): MkWrite[Option[P]] = | ||
MkWrite.derivedOption[P, A] |
File renamed without changes.
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
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