-
Notifications
You must be signed in to change notification settings - Fork 138
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Map encoder with Value class #567
Map encoder with Value class #567
Conversation
f370ae2
to
d947a30
Compare
Codecov Report
@@ Coverage Diff @@
## master #567 +/- ##
==========================================
- Coverage 96.35% 95.54% -0.81%
==========================================
Files 63 63
Lines 1071 1101 +30
Branches 9 8 -1
==========================================
+ Hits 1032 1052 +20
- Misses 39 49 +10
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
d947a30
to
fe18ef2
Compare
|
||
/** | ||
* @tparam F the value class | ||
* @tparam G the single field of the value class | ||
* @tparam H the single field of the value class (with guarantee it's not a `Unit` value) | ||
* @tparam V the inner value type | ||
*/ | ||
implicit def valueClass[F : IsValueClass, G <: ::[_, HNil], H <: ::[_, HNil], V] | ||
implicit def valueClass[F : IsValueClass, G <: ::[_, HNil], H <: ::[_ <: FieldType[_ <: Symbol, _], HNil], K <: Symbol, V, KS <: ::[_ <: Symbol, HNil]] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also capture keys evidence so it can be used to wrap/unwrap in the map/array/collection encoder of Value class
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cchantep thanks for clarifying it.
|
||
implicit val javaBigDecimalEncoder: TypedEncoder[java.math.BigDecimal] = new TypedEncoder[java.math.BigDecimal] { | ||
def nullable: Boolean = false | ||
override def toString: String = "bigDecimalEncoder" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Useful when debuging
@@ -210,29 +226,39 @@ object TypedEncoder { | |||
) | |||
} | |||
|
|||
implicit def arrayEncoder[T: ClassTag](implicit encodeT: TypedEncoder[T]): TypedEncoder[Array[T]] = | |||
implicit def arrayEncoder[T: ClassTag]( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Refactor to support array of Value class with the typeclass RecordFieldEncoder
(rather than the lower TypedEncoder
one)
} | ||
|
||
import shapeless.{HList, LabelledGeneric} | ||
import shapeless.test.illTyped | ||
|
||
import org.scalatest.matchers.should.Matchers | ||
|
||
case class UnitsOnly(a: Unit, b: Unit) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved down
@pomadchin This can be reviewed |
@cchantep wow a solid PR; will take some time to look through that in the beginning of the work week. |
Is that ok for you @pomadchin ? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Checked it on my project and works nice, thanks for this solid and exciting improvement! This PR adds an additional tests coverage as well.
|
||
/** | ||
* @tparam F the value class | ||
* @tparam G the single field of the value class | ||
* @tparam H the single field of the value class (with guarantee it's not a `Unit` value) | ||
* @tparam V the inner value type | ||
*/ | ||
implicit def valueClass[F : IsValueClass, G <: ::[_, HNil], H <: ::[_, HNil], V] | ||
implicit def valueClass[F : IsValueClass, G <: ::[_, HNil], H <: ::[_ <: FieldType[_ <: Symbol, _], HNil], K <: Symbol, V, KS <: ::[_ <: Symbol, HNil]] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cchantep thanks for clarifying it.
@@ -54,15 +55,16 @@ object TypedEncoder { | |||
Invoke(path, "toString", jvmRepr) | |||
} | |||
|
|||
implicit val booleanEncoder: TypedEncoder[Boolean] = new TypedEncoder[Boolean] { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a bit confused by the formatting that happened here, makes it harder to read the diff
i3: Keys.Aux[H, KS], | ||
i4: Values.Aux[H, VS], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need these constrains here?
i3: Keys.Aux[H, KS],
i4: Values.Aux[H, VS]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Required to call RecordFieldEncoder.valueClass
(l80)
Closes #566