diff options
author | Mathias <mathias@decodified.com> | 2017-12-14 14:20:39 +0100 |
---|---|---|
committer | Mathias <mathias@decodified.com> | 2017-12-14 14:26:54 +0100 |
commit | 579cdb1281e7f3e16b13abc591c5e06b1aa32db5 (patch) | |
tree | b0575afd76ebcaa14a09cb42b2ea79f6b916c682 /core/shared/src/main/scala/interface.scala | |
parent | 379f0075ca8042945d8ff89212536894a96f56a8 (diff) | |
download | magnolia-579cdb1281e7f3e16b13abc591c5e06b1aa32db5.tar.gz magnolia-579cdb1281e7f3e16b13abc591c5e06b1aa32db5.tar.bz2 magnolia-579cdb1281e7f3e16b13abc591c5e06b1aa32db5.zip |
Add `CaseClass.rawConstruct` and new `Patcher` example
Diffstat (limited to 'core/shared/src/main/scala/interface.scala')
-rw-r--r-- | core/shared/src/main/scala/interface.scala | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/core/shared/src/main/scala/interface.scala b/core/shared/src/main/scala/interface.scala index 193a6f9..86ef5b1 100644 --- a/core/shared/src/main/scala/interface.scala +++ b/core/shared/src/main/scala/interface.scala @@ -122,7 +122,22 @@ abstract class CaseClass[Typeclass[_], Type] private[magnolia] ( * @param makeParam lambda for converting a generic [[Param]] into the value to be used for * this parameter in the construction of a new instance of the case class * @return a new instance of the case class */ - def construct[Return](makeParam: Param[Typeclass, Type] => Return): Type + final def construct[Return](makeParam: Param[Typeclass, Type] => Return): Type = + rawConstruct(parameters map makeParam) + + /** constructs a new instance of the case class type + * + * Like [[construct]] this method is implemented by Magnolia and let's you construct case class + * instances generically in user code, without knowing their type concretely. + * + * `rawConstruct`, however, is more low-level in that it expects you to provide a [[Seq]] + * containing all the field values for the case class type, in order and with the correct types. + * + * @param fieldValues contains the field values for the case class instance to be constructed, + * in order and with the correct types. + * @return a new instance of the case class + * @throws IllegalArgumentException if the size of `paramValues` differs from the size of [[parameters]] */ + def rawConstruct(fieldValues: Seq[Any]): Type /** a sequence of [[Param]] objects representing all of the parameters in the case class * |