Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
52 additions
and
46 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
17 changes: 0 additions & 17 deletions
17
core/src/main/scala-3/pureconfig/generic/derivation/Labels.scala
This file was deleted.
Oops, something went wrong.
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
35 changes: 35 additions & 0 deletions
35
core/src/main/scala-3/pureconfig/generic/derivation/Utils.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,35 @@ | ||
package pureconfig.generic | ||
package derivation | ||
|
||
import scala.compiletime.{constValue, erasedValue, summonFrom, summonInline} | ||
import scala.deriving.Mirror | ||
|
||
object Utils { | ||
|
||
/** Asserts in compile time that a given value of type `A` is also of type `B`. | ||
* | ||
* @param a | ||
* the value whose type to assert | ||
* @return | ||
* `a` with a widened type. | ||
*/ | ||
inline def widen[A, B](a: A): A & B = | ||
inline a match { case b: B => b } | ||
|
||
/** Materializes the labels of a `A` (e.g. product element names, coproduct options) as a list of strings with an | ||
* optional compile-time transformation. The function is guaranteed to return a constant list. | ||
* | ||
* @param transform | ||
* the function to transform keys with | ||
* @return | ||
* the list of transformed labels. | ||
*/ | ||
inline def transformedLabels[A](inline transform: String => String)(using m: Mirror.Of[A]): List[String] = | ||
transformedLabelsTuple[m.MirroredElemLabels](transform) | ||
|
||
private inline def transformedLabelsTuple[T <: Tuple](inline transform: String => String): List[String] = | ||
inline erasedValue[T] match { | ||
case _: (h *: t) => transform(constValue[h & String]) :: transformedLabelsTuple[t](transform) | ||
case _: EmptyTuple => Nil | ||
} | ||
} |
8 changes: 0 additions & 8 deletions
8
core/src/main/scala-3/pureconfig/generic/derivation/WidenType.scala
This file was deleted.
Oops, something went wrong.