-
Notifications
You must be signed in to change notification settings - Fork 359
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 #2101 from typelevel/add_read_write_generic_back
Add {Write.Read}.generic back to help migrate from earlier versions
- Loading branch information
Showing
15 changed files
with
135 additions
and
72 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
26 changes: 26 additions & 0 deletions
26
modules/core/src/main/scala-2/doobie/util/MkGetPlatform.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 shapeless._ | ||
import shapeless.ops.hlist.IsHCons | ||
|
||
trait MkGetPlatform { | ||
import doobie.util.compat.=:= | ||
|
||
/** @group Instances */ | ||
implicit def unaryProductGet[A, L <: HList, H, T <: HList]( | ||
implicit | ||
G: Generic.Aux[A, L], | ||
C: IsHCons.Aux[L, H, T], | ||
H: Lazy[Get[H]], | ||
E: (H :: HNil) =:= L | ||
): MkGet[A] = { | ||
void(C) // C drives inference but is not used directly | ||
val get = H.value.tmap[A](h => G.from(h :: HNil)) | ||
MkGet.lift(get) | ||
} | ||
|
||
} |
26 changes: 26 additions & 0 deletions
26
modules/core/src/main/scala-2/doobie/util/MkPutPlatform.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 shapeless._ | ||
import shapeless.ops.hlist.IsHCons | ||
|
||
trait MkPutPlatform { | ||
import doobie.util.compat.=:= | ||
|
||
/** @group Instances */ | ||
implicit def unaryProductPut[A, L <: HList, H, T <: HList]( | ||
implicit | ||
G: Generic.Aux[A, L], | ||
C: IsHCons.Aux[L, H, T], | ||
H: Lazy[Put[H]], | ||
E: (H :: HNil) =:= L | ||
): MkPut[A] = { | ||
void(E) // E is a necessary constraint but isn't used directly | ||
val put = H.value.contramap[A](a => G.to(a).head) | ||
MkPut.lift(put) | ||
} | ||
|
||
} |
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
20 changes: 20 additions & 0 deletions
20
modules/core/src/main/scala-3/doobie/util/MkGetPlatform.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,20 @@ | ||
// 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 MkGetPlatform: | ||
|
||
// Get is available for single-element products. | ||
given unaryProductGet[P <: Product, A]( | ||
using | ||
p: Mirror.ProductOf[P], | ||
i: p.MirroredElemTypes =:= (A *: EmptyTuple), | ||
g: Get[A] | ||
): MkGet[P] = { | ||
val get = g.map(a => p.fromProduct(a *: EmptyTuple)) | ||
MkGet.lift(get) | ||
} |
20 changes: 20 additions & 0 deletions
20
modules/core/src/main/scala-3/doobie/util/MkPutPlatform.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,20 @@ | ||
// 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 MkPutPlatform: | ||
|
||
// Put is available for single-element products. | ||
given unaryProductPut[P <: Product, A]( | ||
using | ||
m: Mirror.ProductOf[P], | ||
i: m.MirroredElemTypes =:= (A *: EmptyTuple), | ||
p: Put[A] | ||
): MkPut[P] = { | ||
val put: Put[P] = p.contramap(p => i(Tuple.fromProductTyped(p)).head) | ||
MkPut.lift(put) | ||
} |
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