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

Renamed params in caseclass to unify the interface between two versions #459

Merged
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
10 changes: 5 additions & 5 deletions src/core/impl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ object CaseClassDerivation:
inline def fromMirror[Typeclass[_], A](
product: Mirror.ProductOf[A]
): CaseClass[Typeclass, A] =
val parameters = IArray(
val params = IArray(
paramsFromMaps[
Typeclass,
A,
Expand All @@ -29,21 +29,21 @@ object CaseClassDerivation:
typeInfo[A],
isObject[A],
isValueClass[A],
parameters,
params,
IArray(anns[A]*),
IArray(inheritedAnns[A]*),
IArray[Any](typeAnns[A]*)
):
def construct[PType: ClassTag](makeParam: Param => PType): A =
product.fromProduct(Tuple.fromArray(params.map(makeParam).to(Array)))
product.fromProduct(Tuple.fromArray(parameters.map(makeParam).to(Array)))

def rawConstruct(fieldValues: Seq[Any]): A =
product.fromProduct(Tuple.fromArray(fieldValues.to(Array)))

def constructEither[Err, PType: ClassTag](
makeParam: Param => Either[Err, PType]
): Either[List[Err], A] =
params
parameters
.map(makeParam)
.foldLeft[Either[List[Err], Array[PType]]](Right(Array())) {
case (Left(errs), Left(err)) => Left(errs ++ List(err))
Expand All @@ -58,7 +58,7 @@ object CaseClassDerivation:
): M[A] = {
val m = summon[Monadic[M]]
m.map {
params.map(makeParam).foldLeft(m.point(Array())) { (accM, paramM) =>
parameters.map(makeParam).foldLeft(m.point(Array())) { (accM, paramM) =>
m.flatMap(accM) { acc =>
m.map(paramM)(acc ++ List(_))
}
Expand Down
12 changes: 7 additions & 5 deletions src/core/interface.scala
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ end CaseClass
/**
* In the terminology of Algebraic Data Types (ADTs), case classes are known as 'product types'.
*
* @param params an array giving information about the parameters of the case class. Each [[Param]] element
* @param parameters an array giving information about the parameters of the case class. Each [[Param]] element
* has a very useful [[CaseClass.Param.typeclass]] field giving the constructed typeclass for the
* parameter's type. Eg for a `case class Foo(bar: String, baz: Int)`, you can
* obtain `Typeclass[String]`, `Typeclass[Int]`.
Expand All @@ -106,7 +106,7 @@ abstract class CaseClass[Typeclass[_], Type](
val typeInfo: TypeInfo,
val isObject: Boolean,
val isValueClass: Boolean,
val params: IArray[CaseClass.Param[Typeclass, Type]],
val parameters: IArray[CaseClass.Param[Typeclass, Type]],
val annotations: IArray[Any],
val inheritedAnnotations: IArray[Any] = IArray.empty[Any],
val typeAnnotations: IArray[Any]
Expand All @@ -117,23 +117,25 @@ abstract class CaseClass[Typeclass[_], Type](
typeInfo: TypeInfo,
isObject: Boolean,
isValueClass: Boolean,
params: IArray[CaseClass.Param[Typeclass, Type]],
parameters: IArray[CaseClass.Param[Typeclass, Type]],
annotations: IArray[Any],
typeAnnotations: IArray[Any]
) = this(
typeInfo,
isObject,
isValueClass,
params,
parameters,
annotations,
IArray.empty[Any],
typeAnnotations
)

def params: IArray[CaseClass.Param[Typeclass, Type]] = parameters

type Param = CaseClass.Param[Typeclass, Type]

override def toString: String =
s"CaseClass(${typeInfo.full}, ${params.mkString(",")})"
s"CaseClass(${typeInfo.full}, ${parameters.mkString(",")})"
def construct[PType](makeParam: Param => PType)(using ClassTag[PType]): Type
def constructMonadic[Monad[_]: Monadic, PType: ClassTag](
make: Param => Monad[PType]
Expand Down