Skip to content

Commit

Permalink
Revert "Support for value classes"
Browse files Browse the repository at this point in the history
  • Loading branch information
micsza authored Dec 22, 2022
1 parent 465a30f commit f5df7e6
Show file tree
Hide file tree
Showing 8 changed files with 209 additions and 645 deletions.
54 changes: 0 additions & 54 deletions src/core/impl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,59 +7,6 @@ import scala.reflect.*
import Macro.*

object CaseClassDerivation:

inline def valueClassDerivation[TC[_], V]: CaseClass[TC, V] =

val theParam: CaseClass.Param[TC, V] =
Macro.ValueClassDerivation.getValueClassParam[TC, V]

new CaseClass[TC, V](
typeInfo = typeInfo[V],
isObject = isObject[V],
isValueClass = true,
params = IArray.from(theParam :: Nil),
annotations = IArray.from(anns[V]),
inheritedAnnotations = IArray.from(inheritedAnns[V]),
typeAnnotations = IArray.from(typeAnns[V])
):

def rawConstruct(fieldValues: Seq[Any]): V =
Macro.ValueClassDerivation.rawContructByMacro[V](fieldValues.toList)

def construct[PType: ClassTag](makeParam: Param => PType): V =
Macro.ValueClassDerivation.rawContructByMacro[V](
params.map(makeParam).toList
)

def constructEither[Err, PType: ClassTag](
makeParam: Param => Either[Err, PType]
): Either[List[Err], V] =
params
.map(makeParam)
.foldLeft[Either[List[Err], Array[PType]]](Right(Array())) {
case (Left(errs), Left(err)) => Left(errs ++ List(err))
case (Right(acc), Right(param)) => Right(acc ++ Array(param))
case (errs @ Left(_), _) => errs
case (_, Left(err)) => Left(List(err))
}
.map { params =>
Macro.ValueClassDerivation.rawContructByMacro[V](params.toList)
}

def constructMonadic[M[_]: Monadic, PType: ClassTag](
makeParam: Param => M[PType]
): M[V] =
val m = summon[Monadic[M]]
m.map {
params.map(makeParam).foldLeft(m.point(Array())) { (accM, paramM) =>
m.flatMap(accM) { acc =>
m.map(paramM)(acc ++ List(_))
}
}
} { params =>
Macro.ValueClassDerivation.rawContructByMacro[V](params.toList)
}

inline def fromMirror[Typeclass[_], A](
product: Mirror.ProductOf[A]
): CaseClass[Typeclass, A] =
Expand Down Expand Up @@ -150,7 +97,6 @@ object CaseClassDerivation:
defaults,
idx + 1
)

end CaseClassDerivation

trait SealedTraitDerivation:
Expand Down
3 changes: 1 addition & 2 deletions src/core/interface.scala
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ object CaseClass:
override def toString: String = s"Param($label)"

object Param:

def apply[F[_], T, P](
name: String,
idx: Int,
Expand All @@ -64,7 +63,7 @@ object CaseClass:
):
type PType = P
def default: Option[PType] = defaultVal.value
def typeclass: F[PType] = cbn.value
def typeclass = cbn.value
override def inheritedAnnotations = inheritedAnns
def deref(value: T): P =
value.asInstanceOf[Product].productElement(idx).asInstanceOf[P]
Expand Down
Loading

0 comments on commit f5df7e6

Please sign in to comment.