Skip to content
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

Deprecate withCoproductInstance name #500

Merged
merged 3 commits into from
Apr 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class Coproduct extends CommonBenchmarkSettings {
private val color2ChannelT = Transformer.derive[Color, Channel]
private val channel2ColorT = Transformer
.define[Channel, Color]
.withCoproductInstance { (_: Channel.Alpha.type) =>
.withSealedSubtypeHandled { (_: Channel.Alpha.type) =>
Color.Blue
}
.buildTransformer
Expand All @@ -31,7 +31,7 @@ class Coproduct extends CommonBenchmarkSettings {
color
.transformInto[Channel]
.into[Color]
.withCoproductInstance { (_: Channel.Alpha.type) =>
.withSealedSubtypeHandled { (_: Channel.Alpha.type) =>
Color.Blue
}
.transform
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class ProtobufOneOfSpec extends ChimneySpec {

pbType.value
.intoPartial[addressbook.AddressBookType]
.withCoproductInstancePartial[pb.addressbook.AddressBookType.Value.Empty.type](_ => partial.Result.fromEmpty)
.withSealedSubtypeHandledPartial[pb.addressbook.AddressBookType.Value.Empty.type](_ => partial.Result.fromEmpty)
.transform
.asOption ==> Some(domainType)
locally {
Expand All @@ -40,8 +40,8 @@ class ProtobufOneOfSpec extends ChimneySpec {

pbStatus
.intoPartial[order.CustomerStatus]
.withCoproductInstancePartial[pb.order.CustomerStatus.Empty.type](_ => partial.Result.fromEmpty)
.withCoproductInstance[pb.order.CustomerStatus.NonEmpty](_.transformInto[order.CustomerStatus])
.withSealedSubtypeHandledPartial[pb.order.CustomerStatus.Empty.type](_ => partial.Result.fromEmpty)
.withSealedSubtypeHandled[pb.order.CustomerStatus.NonEmpty](_.transformInto[order.CustomerStatus])
.transform
.asOption ==> Some(domainStatus)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,45 +123,93 @@ final class PartialTransformerDefinition[From, To, Overrides <: TransformerOverr
): PartialTransformerDefinition[From, To, ? <: TransformerOverrides, Flags] =
macro PartialTransformerDefinitionMacros.withFieldRenamedImpl[From, To, Overrides, Flags]

/** Use `f` to calculate the (missing) coproduct instance when mapping one coproduct into another.
/** Use `f` to calculate the unmatched subtype when mapping one sealed/enum into another.
*
* By default if mapping one coproduct in `From` into another coproduct in `To` derivation
* expects that coproducts to have matching names of its components, and for every component
* in `To` field's type there is matching component in `From` type. If some component is missing
* it fails compilation unless provided replacement with this operation.
*
* For convenience/readability [[withEnumCaseHandled]] alias can be used (e.g. for Scala 3 enums or Java enums).
*
* It differs from `withFieldComputed(_.matching[Subtype], src => ...)`, since `withSealedSubtypeHandled` matches on
* `From` subtype, while `.matching[Subtype]` matches on `To` value's piece.
*
* @see [[https://chimney.readthedocs.io/supported-transformations/#handling-a-specific-sealed-subtype-with-a-computed-value]] for more details
*
* @tparam Subtypetype of coproduct instance
* @tparam Subtype type of sealed/enum instance
* @param f function to calculate values of components that cannot be mapped automatically
* @return [[io.scalaland.chimney.dsl.PartialTransformerDefinition]]
*
* @since 1.0.0
*/
def withSealedSubtypeHandled[Subtype](
f: Subtype => To
): PartialTransformerDefinition[From, To, ? <: TransformerOverrides, Flags] =
macro PartialTransformerDefinitionMacros.withSealedSubtypeHandledImpl[From, To, Overrides, Flags, Subtype]

/** Alias to [[withSealedSubtypeHandled]].
*
* @since 1.0.0
*/
def withEnumCaseHandled[Subtype](
f: Subtype => To
): PartialTransformerDefinition[From, To, ? <: TransformerOverrides, Flags] =
macro PartialTransformerDefinitionMacros.withSealedSubtypeHandledImpl[From, To, Overrides, Flags, Subtype]

/** Renamed to [[withSealedSubtypeHandled]].
*
* @since 0.7.0
*/
@deprecated("Use .withSealedSubtypeHandled or .withEnumCaseHandled for more clarity", "1.0.0")
def withCoproductInstance[Subtype](
f: Subtype => To
): PartialTransformerDefinition[From, To, ? <: TransformerOverrides, Flags] =
macro PartialTransformerDefinitionMacros.withCoproductInstanceImpl[From, To, Overrides, Flags, Subtype]
macro PartialTransformerDefinitionMacros.withSealedSubtypeHandledImpl[From, To, Overrides, Flags, Subtype]

/** Use `f` to calculate the (missing) coproduct instance partial result when mapping one coproduct into another.
/** Use `f` to calculate the unmatched subtype's partial.Result when mapping one sealed/enum into another.
*
* By default if mapping one coproduct in `From` into another coproduct in `To` derivation
* expects that coproducts to have matching names of its components, and for every component
* in `To` field's type there is matching component in `From` type. If some component is missing
* it fails compilation unless provided replacement with this operation.
*
* For convenience/readability [[withEnumCaseHandledPartial]] alias can be used (e.g. for Scala 3 enums or Java enums).
*
* It differs from `withFieldComputedPartial(_.matching[Subtype], src => ...)`, since `withSealedSubtypeHandled` matches on
* `From` subtype, while `.matching[Subtype]` matches on `To` value's piece.
*
* @see [[https://chimney.readthedocs.io/supported-transformations/#handling-a-specific-sealed-subtype-with-a-computed-value]] for more details
*
* @tparam Subtypetype of coproduct instance
* @tparam Subtype type of sealed/enum instance
* @param f function to calculate values of components that cannot be mapped automatically
* @return [[io.scalaland.chimney.dsl.PartialTransformerDefinition]]
*
* @since 0.7.0
*/
def withSealedSubtypeHandledPartial[Subtype](
f: Subtype => partial.Result[To]
): PartialTransformerDefinition[From, To, ? <: TransformerOverrides, Flags] =
macro PartialTransformerDefinitionMacros.withSealedSubtypeHandledPartialImpl[From, To, Overrides, Flags, Subtype]

/** Alias to [[withSealedSubtypeHandledPartial]].
*
* @since 1.0.0
*/
def withEnumCaseHandledPartial[Subtype](
f: Subtype => partial.Result[To]
): PartialTransformerDefinition[From, To, ? <: TransformerOverrides, Flags] =
macro PartialTransformerDefinitionMacros.withSealedSubtypeHandledPartialImpl[From, To, Overrides, Flags, Subtype]

/** Renamed to [[withSealedSubtypeHandledPartial]].
*
* @since 0.7.0
*/
@deprecated("Use .withSealedSubtypeHandledPartial or .withEnumCaseHandledPartial for more clarity", "1.0.0")
def withCoproductInstancePartial[Subtype](
f: Subtype => partial.Result[To]
): PartialTransformerDefinition[From, To, ? <: TransformerOverrides, Flags] =
macro PartialTransformerDefinitionMacros.withCoproductInstancePartialImpl[From, To, Overrides, Flags, Subtype]
macro PartialTransformerDefinitionMacros.withSealedSubtypeHandledPartialImpl[From, To, Overrides, Flags, Subtype]

/** Use `f` instead of the primary constructor to construct the `To` value.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,45 +126,93 @@ final class PartialTransformerInto[From, To, Overrides <: TransformerOverrides,
): PartialTransformerInto[From, To, ? <: TransformerOverrides, Flags] =
macro PartialTransformerIntoMacros.withFieldRenamedImpl[From, To, Overrides, Flags]

/** Use `f` to calculate the (missing) coproduct instance when mapping one coproduct into another.
/** Use `f` to calculate the unmatched subtype when mapping one sealed/enum into another.
*
* By default if mapping one coproduct in `From` into another coproduct in `To` derivation
* expects that coproducts to have matching names of its components, and for every component
* in `To` field's type there is matching component in `From` type. If some component is missing
* it fails compilation unless provided replacement with this operation.
*
* For convenience/readability [[withEnumCaseHandled]] alias can be used (e.g. for Scala 3 enums or Java enums).
*
* It differs from `withFieldComputed(_.matching[Subtype], src => ...)`, since `withSealedSubtypeHandled` matches on
* `From` subtype, while `.matching[Subtype]` matches on `To` value's piece.
*
* @see [[https://chimney.readthedocs.io/supported-transformations/#handling-a-specific-sealed-subtype-with-a-computed-value]] for more details
*
* @tparam Subtypetype of coproduct instance
* @tparam Subtype type of sealed/enum instance
* @param f function to calculate values of components that cannot be mapped automatically
* @return [[io.scalaland.chimney.dsl.PartialTransformerInto]]
*
* @since 1.0.0
*/
def withSealedSubtypeHandled[Subtype](
f: Subtype => To
): PartialTransformerInto[From, To, ? <: TransformerOverrides, Flags] =
macro PartialTransformerIntoMacros.withSealedSubtypeHandledImpl[From, To, Overrides, Flags, Subtype]

/** Alias to [[withSealedSubtypeHandled]].
*
* @since 1.0.0
*/
def withEnumCaseHandled[Subtype](
f: Subtype => To
): PartialTransformerInto[From, To, ? <: TransformerOverrides, Flags] =
macro PartialTransformerIntoMacros.withSealedSubtypeHandledImpl[From, To, Overrides, Flags, Subtype]

/** Renamed to [[withSealedSubtypeHandled]].
*
* @since 0.7.0
*/
@deprecated("Use .withSealedSubtypeHandled or .withEnumCaseHandled for more clarity", "1.0.0")
def withCoproductInstance[Subtype](
f: Subtype => To
): PartialTransformerInto[From, To, ? <: TransformerOverrides, Flags] =
macro PartialTransformerIntoMacros.withCoproductInstanceImpl[From, To, Overrides, Flags, Subtype]
macro PartialTransformerIntoMacros.withSealedSubtypeHandledImpl[From, To, Overrides, Flags, Subtype]

/** Use `f` to calculate the (missing) coproduct instance partial result when mapping one coproduct into another.
/** Use `f` to calculate the unmatched subtype's partial.Result when mapping one sealed/enum into another.
*
* By default if mapping one coproduct in `From` into another coproduct in `To` derivation
* expects that coproducts to have matching names of its components, and for every component
* in `To` field's type there is matching component in `From` type. If some component is missing
* it fails compilation unless provided replacement with this operation.
*
* For convenience/readability [[withEnumCaseHandledPartial]] alias can be used (e.g. for Scala 3 enums or Java enums).
*
* It differs from `withFieldComputedPartial(_.matching[Subtype], src => ...)`, since `withSealedSubtypeHandled` matches on
* `From` subtype, while `.matching[Subtype]` matches on `To` value's piece.
*
* @see [[https://chimney.readthedocs.io/supported-transformations/#handling-a-specific-sealed-subtype-with-a-computed-value]] for more details
*
* @tparam Subtypetype of coproduct instance
* @tparam Subtype type of sealed/enum instance
* @param f function to calculate values of components that cannot be mapped automatically
* @return [[io.scalaland.chimney.dsl.PartialTransformerInto]]
*
* @since 1.0.0
*/
def withSealedSubtypeHandledPartial[Subtype](
f: Subtype => partial.Result[To]
): PartialTransformerInto[From, To, ? <: TransformerOverrides, Flags] =
macro PartialTransformerIntoMacros.withSealedSubtypeHandledPartialImpl[From, To, Overrides, Flags, Subtype]

/** Alias to [[withSealedSubtypeHandledPartial]].
*
* @since 1.0.0
*/
def withEnumCaseHandledPartial[Subtype](
f: Subtype => partial.Result[To]
): PartialTransformerInto[From, To, ? <: TransformerOverrides, Flags] =
macro PartialTransformerIntoMacros.withSealedSubtypeHandledPartialImpl[From, To, Overrides, Flags, Subtype]

/** Renamed to [[withSealedSubtypeHandledPartial]].
*
* @since 0.7.0
*/
@deprecated("Use .withSealedSubtypeHandledPartial or .withEnumCaseHandledPartial for more clarity", "1.0.0")
def withCoproductInstancePartial[Subtype](
f: Subtype => partial.Result[To]
): PartialTransformerInto[From, To, ? <: TransformerOverrides, Flags] =
macro PartialTransformerIntoMacros.withCoproductInstancePartialImpl[From, To, Overrides, Flags, Subtype]
macro PartialTransformerIntoMacros.withSealedSubtypeHandledPartialImpl[From, To, Overrides, Flags, Subtype]

/** Use `f` instead of the primary constructor to construct the `To` value.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,25 +94,49 @@ final class TransformerDefinition[From, To, Overrides <: TransformerOverrides, F
): TransformerDefinition[From, To, ? <: TransformerOverrides, Flags] =
macro TransformerDefinitionMacros.withFieldRenamedImpl[From, To, Overrides, Flags]

/** Use `f` to calculate the (missing) coproduct instance when mapping one coproduct into another.
/** Use `f` to calculate the unmatched subtype when mapping one sealed/enum into another.
*
* By default if mapping one coproduct in `From` into another coproduct in `To` derivation
* expects that coproducts to have matching names of its components, and for every component
* in `To` field's type there is matching component in `From` type. If some component is missing
* it fails compilation unless provided replacement with this operation.
*
* For convenience/readability [[withEnumCaseHandled]] alias can be used (e.g. for Scala 3 enums or Java enums).
*
* It differs from `withFieldComputed(_.matching[Subtype], src => ...)`, since `withSealedSubtypeHandled` matches on
* `From` subtype, while `.matching[Subtype]` matches on `To` value's piece.
*
* @see [[https://chimney.readthedocs.io/supported-transformations/#handling-a-specific-sealed-subtype-with-a-computed-value]] for more details
*
* @tparam Subtypetype of coproduct instance
* @tparam Subtype type of sealed/enum instance
* @param f function to calculate values of components that cannot be mapped automatically
* @return [[io.scalaland.chimney.dsl.TransformerDefinition]]
*
* @since 1.0.0
*/
def withSealedSubtypeHandled[Subtype](
f: Subtype => To
): TransformerDefinition[From, To, ? <: TransformerOverrides, Flags] =
macro TransformerDefinitionMacros.withSealedSubtypeHandledImpl[From, To, Overrides, Flags, Subtype]

/** Alias to [[withSealedSubtypeHandled]].
*
* @since 1.0.0
*/
def withEnumCaseHandled[Subtype](
f: Subtype => To
): TransformerDefinition[From, To, ? <: TransformerOverrides, Flags] =
macro TransformerDefinitionMacros.withSealedSubtypeHandledImpl[From, To, Overrides, Flags, Subtype]

/** Renamed to [[withSealedSubtypeHandled]].
*
* @since 0.4.0
*/
@deprecated("Use .withSealedSubtypeHandled or .withEnumCaseHandled for more clarity", "1.0.0")
def withCoproductInstance[Subtype](
f: Subtype => To
): TransformerDefinition[From, To, ? <: TransformerOverrides, Flags] =
macro TransformerDefinitionMacros.withCoproductInstanceImpl[From, To, Overrides, Flags, Subtype]
macro TransformerDefinitionMacros.withSealedSubtypeHandledImpl[From, To, Overrides, Flags, Subtype]

/** Use `f` instead of the primary constructor to construct the `To` value.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,36 @@ final class TransformerInto[From, To, Overrides <: TransformerOverrides, Flags <
* in `To` field's type there is matching component in `From` type. If some component is missing
* it will fail.
*
* For convenience/readability [[withEnumCaseHandled]] alias can be used (e.g. for Scala 3 enums or Java enums).
*
* It differs from `withFieldComputed(_.matching[Subtype], src => ...)`, since `withSealedSubtypeHandled` matches on
* `From` subtype, while `.matching[Subtype]` matches on `To` value's piece.
*
* @see [[https://chimney.readthedocs.io/supported-transformations/#handling-a-specific-sealed-subtype-with-a-computed-value]] for more details
*
* @tparam Subtypetype of coproduct instance@param f function to calculate values of components that cannot be mapped automatically
* @tparam Subtype type of sealed/enum instance
* @param f function to calculate values of components that cannot be mapped automatically
* @return [[io.scalaland.chimney.dsl.TransformerInto]]
*
* @since 1.0.0
*/
def withSealedSubtypeHandled[Subtype](f: Subtype => To): TransformerInto[From, To, ? <: TransformerOverrides, Flags] =
macro TransformerIntoMacros.withSealedSubtypeHandledImpl[From, To, Overrides, Flags, Subtype]

/** Alias to [[withSealedSubtypeHandled]].
*
* @since 1.0.0
*/
def withEnumCaseHandled[Subtype](f: Subtype => To): TransformerInto[From, To, ? <: TransformerOverrides, Flags] =
macro TransformerIntoMacros.withSealedSubtypeHandledImpl[From, To, Overrides, Flags, Subtype]

/** Renamed to [[withSealedSubtypeHandled]].
*
* @since 0.1.2
*/
@deprecated("Use .withSealedSubtypeHandled or .withEnumCaseHandled for more clarity", "1.0.0")
def withCoproductInstance[Subtype](f: Subtype => To): TransformerInto[From, To, ? <: TransformerOverrides, Flags] =
macro TransformerIntoMacros.withCoproductInstanceImpl[From, To, Overrides, Flags, Subtype]
macro TransformerIntoMacros.withSealedSubtypeHandledImpl[From, To, Overrides, Flags, Subtype]

/** Use `f` instead of the primary constructor to construct the `To` value.
*
Expand All @@ -121,9 +142,9 @@ final class TransformerInto[From, To, Overrides <: TransformerOverrides, Flags <
*
* @since 0.8.4
*/
def withConstructor[Ctor](
f: Ctor
)(implicit ev: IsFunction.Of[Ctor, To]): TransformerInto[From, To, ? <: TransformerOverrides, Flags] =
def withConstructor[Ctor](f: Ctor)(implicit
ev: IsFunction.Of[Ctor, To]
): TransformerInto[From, To, ? <: TransformerOverrides, Flags] =
macro TransformerIntoMacros.withConstructorImpl[From, To, Overrides, Flags]

/** Apply configured transformation in-place.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@
}.applyFromSelectors(selectorFrom, selectorTo)
)

def withCoproductInstanceImpl[
def withSealedSubtypeHandledImpl[
From: WeakTypeTag,

Check warning on line 83 in chimney/src/main/scala-2/io/scalaland/chimney/internal/compiletime/dsl/PartialTransformerDefinitionMacros.scala

View check run for this annotation

Codecov / codecov/patch

chimney/src/main/scala-2/io/scalaland/chimney/internal/compiletime/dsl/PartialTransformerDefinitionMacros.scala#L82-L83

Added lines #L82 - L83 were not covered by tests
To: WeakTypeTag,
Overrides <: TransformerOverrides: WeakTypeTag,
Flags <: TransformerFlags: WeakTypeTag,
Expand All @@ -96,7 +96,7 @@
]]
}.applyJavaEnumFixFromClosureSignature[Subtype](f)

def withCoproductInstancePartialImpl[
def withSealedSubtypeHandledPartialImpl[
From: WeakTypeTag,
To: WeakTypeTag,
Overrides <: TransformerOverrides: WeakTypeTag,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class PartialTransformerIntoMacros(val c: whitebox.Context) extends utils.DslMac
}.applyFromSelectors(selectorFrom, selectorTo)
)

def withCoproductInstanceImpl[
def withSealedSubtypeHandledImpl[
From: WeakTypeTag,
To: WeakTypeTag,
Overrides <: TransformerOverrides: WeakTypeTag,
Expand All @@ -97,7 +97,7 @@ class PartialTransformerIntoMacros(val c: whitebox.Context) extends utils.DslMac
]]
}.applyJavaEnumFixFromClosureSignature[Subtype](f)

def withCoproductInstancePartialImpl[
def withSealedSubtypeHandledPartialImpl[
From: WeakTypeTag,
To: WeakTypeTag,
Overrides <: TransformerOverrides: WeakTypeTag,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class TransformerDefinitionMacros(val c: whitebox.Context) extends utils.DslMacr
}.applyFromSelectors(selectorFrom, selectorTo)
)

def withCoproductInstanceImpl[
def withSealedSubtypeHandledImpl[
From: WeakTypeTag,
To: WeakTypeTag,
Overrides <: TransformerOverrides: WeakTypeTag,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class TransformerIntoMacros(val c: whitebox.Context) extends utils.DslMacroUtils
}.applyFromSelectors(selectorFrom, selectorTo)
)

def withCoproductInstanceImpl[
def withSealedSubtypeHandledImpl[
From: WeakTypeTag,
To: WeakTypeTag,
Overrides <: TransformerOverrides: WeakTypeTag,
Expand Down
Loading
Loading