diff options
author | Jon Pretty <jon.pretty@propensive.com> | 2017-12-29 15:47:32 +0000 |
---|---|---|
committer | Jon Pretty <jon.pretty@propensive.com> | 2017-12-29 15:47:32 +0000 |
commit | 436c04954d6973aa60c59dc835bc3573b72b6bc2 (patch) | |
tree | 097d154d7787f548028e2cc02267bedaccc610e9 /core/shared/src/main/scala/interface.scala | |
parent | e315da3704c39cd5f0760524b18b5839f363f423 (diff) | |
parent | 051042daf4569f48ff7062c70142df4fbd2e79b5 (diff) | |
download | magnolia-436c04954d6973aa60c59dc835bc3573b72b6bc2.tar.gz magnolia-436c04954d6973aa60c59dc835bc3573b72b6bc2.tar.bz2 magnolia-436c04954d6973aa60c59dc835bc3573b72b6bc2.zip |
Merge branch 'sirthias-md/rawconstruct'
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 a82a54c..b06f350 100644 --- a/core/shared/src/main/scala/interface.scala +++ b/core/shared/src/main/scala/interface.scala @@ -123,7 +123,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 * |