diff --git a/src/core/wisteria.ProductDerivationMethods.scala b/src/core/wisteria.ProductDerivationMethods.scala index af6725e..da4444e 100644 --- a/src/core/wisteria.ProductDerivationMethods.scala +++ b/src/core/wisteria.ProductDerivationMethods.scala @@ -25,14 +25,13 @@ import scala.compiletime.* trait ProductDerivationMethods[TypeclassType[_]]: protected transparent inline def construct[DerivationType <: Product] - (using reflection: ProductReflection[DerivationType], requirement: ContextRequirement) - (inline lambda: [FieldType] => + (using reflection: ProductReflection[DerivationType], requirement: ContextRequirement) + (inline lambda: [FieldType] => requirement.Optionality[TypeclassType[FieldType]] => - (typeclass: requirement.Optionality[TypeclassType[FieldType]], - default: Default[Optional[FieldType]], - label: Text, - index: Int & FieldIndex[FieldType]) ?=> - FieldType) + (typeclass: requirement.Optionality[TypeclassType[FieldType]], + default: Default[Optional[FieldType]], + label: Text, + index: Int & FieldIndex[FieldType]) ?=> FieldType) : DerivationType = type Fields = reflection.MirroredElemTypes @@ -44,20 +43,19 @@ trait ProductDerivationMethods[TypeclassType[_]]: .reverse protected transparent inline def constructWith[ConstructorType[_]] - (using requirement: ContextRequirement) - [DerivationType <: Product] - (using reflection: ProductReflection[DerivationType]) - (inline bind: [InputType, OutputType] => ConstructorType[InputType] => - (InputType => ConstructorType[OutputType]) => - ConstructorType[OutputType], - inline pure: [MonadicType] => MonadicType => ConstructorType[MonadicType], - inline lambda: [FieldType] => - requirement.Optionality[TypeclassType[FieldType]] => - (typeclass: requirement.Optionality[TypeclassType[FieldType]], - default: Default[Optional[FieldType]], - label: Text, - index: Int & FieldIndex[FieldType]) ?=> - ConstructorType[FieldType]) + (using requirement: ContextRequirement) + [DerivationType <: Product] + (using reflection: ProductReflection[DerivationType]) + (inline bind: [InputType, OutputType] => ConstructorType[InputType] => + (InputType => ConstructorType[OutputType]) => ConstructorType[OutputType], + inline pure: [MonadicType] => MonadicType => ConstructorType[MonadicType], + inline lambda: [FieldType] => + requirement.Optionality[TypeclassType[FieldType]] => + (typeclass: requirement.Optionality[TypeclassType[FieldType]], + default: Default[Optional[FieldType]], + label: Text, + index: Int & FieldIndex[FieldType]) ?=> + ConstructorType[FieldType]) : ConstructorType[DerivationType] = type Fields = reflection.MirroredElemTypes @@ -75,16 +73,15 @@ trait ProductDerivationMethods[TypeclassType[_]]: pure(reflection.fromProduct(tuple.reverse)) protected transparent inline def contexts[DerivationType <: Product] - (using reflection: ProductReflection[DerivationType], requirement: ContextRequirement) - [ResultType] - (inline lambda: [FieldType] => - requirement.Optionality[TypeclassType[FieldType]] => - (typeclass: requirement.Optionality[TypeclassType[FieldType]], - default: Default[Optional[FieldType]], - label: Text, - dereference: DerivationType => FieldType, - index: Int & FieldIndex[FieldType]) ?=> - ResultType) + (using reflection: ProductReflection[DerivationType], requirement: ContextRequirement) + [ResultType] + (inline lambda: [FieldType] => + requirement.Optionality[TypeclassType[FieldType]] => + (typeclass: requirement.Optionality[TypeclassType[FieldType]], + default: Default[Optional[FieldType]], + label: Text, + dereference: DerivationType => FieldType, + index: Int & FieldIndex[FieldType]) ?=> ResultType) : IArray[ResultType] = type Fields = reflection.MirroredElemTypes @@ -109,10 +106,10 @@ trait ProductDerivationMethods[TypeclassType[_]]: case _ => false protected transparent inline def complement[DerivationType <: Product, FieldType] - (product: DerivationType) - (using fieldIndex: Int & FieldIndex[FieldType], - reflection: ProductReflection[DerivationType], - requirement: ContextRequirement) + (product: DerivationType) + (using fieldIndex: Int & FieldIndex[FieldType], + reflection: ProductReflection[DerivationType], + requirement: ContextRequirement) : FieldType = type Labels = reflection.MirroredElemLabels @@ -125,16 +122,15 @@ trait ProductDerivationMethods[TypeclassType[_]]: .vouch(using Unsafe) protected transparent inline def fields[DerivationType <: Product](inline product: DerivationType) - (using requirement: ContextRequirement) - (using reflection: ProductReflection[DerivationType]) - [ResultType] - (inline lambda: [FieldType] => - FieldType => - (context: requirement.Optionality[TypeclassType[FieldType]], - default: Default[Optional[FieldType]], - label: Text, - index: Int & FieldIndex[FieldType]) ?=> - ResultType) + (using requirement: ContextRequirement) + (using reflection: ProductReflection[DerivationType]) + [ResultType] + (inline lambda: [FieldType] => + FieldType => + (context: requirement.Optionality[TypeclassType[FieldType]], + default: Default[Optional[FieldType]], + label: Text, + index: Int & FieldIndex[FieldType]) ?=> ResultType) : IArray[ResultType] = summonInline[ClassTag[ResultType]].give: @@ -155,17 +151,16 @@ trait ProductDerivationMethods[TypeclassType[_]]: // erasedness of the tuple. private transparent inline def fold - [DerivationType <: Product, FieldsType <: Tuple, LabelsType <: Tuple, ResultType] - (using requirement: ContextRequirement) - (inline tuple: FieldsType, accumulator: ResultType, index: Int) - (inline lambda: ResultType => - [FieldType] => - FieldType => - (context: Optional[TypeclassType[FieldType]], - default: Default[Optional[FieldType]], - label: Text, - index: Int & FieldIndex[FieldType]) ?=> - ResultType) + [DerivationType <: Product, FieldsType <: Tuple, LabelsType <: Tuple, ResultType] + (using requirement: ContextRequirement) + (inline tuple: FieldsType, accumulator: ResultType, index: Int) + (inline lambda: ResultType => + [FieldType] => + FieldType => + (context: Optional[TypeclassType[FieldType]], + default: Default[Optional[FieldType]], + label: Text, + index: Int & FieldIndex[FieldType]) ?=> ResultType) : ResultType = inline tuple match @@ -192,17 +187,16 @@ trait ProductDerivationMethods[TypeclassType[_]]: (lambda) private transparent inline def fold - [DerivationType <: Product, FieldsType <: Tuple, LabelsType <: Tuple, ResultType] - (using requirement: ContextRequirement) - (inline accumulator: ResultType, index: Int) - (inline lambda: ResultType => - [FieldType] => - requirement.Optionality[TypeclassType[FieldType]] => - (default: Default[Optional[FieldType]], - label: Text, - dereference: DerivationType => FieldType, - index: Int & FieldIndex[FieldType]) ?=> - ResultType) + [DerivationType <: Product, FieldsType <: Tuple, LabelsType <: Tuple, ResultType] + (using requirement: ContextRequirement) + (inline accumulator: ResultType, index: Int) + (inline lambda: ResultType => + [FieldType] => + requirement.Optionality[TypeclassType[FieldType]] => + (default: Default[Optional[FieldType]], + label: Text, + dereference: DerivationType => FieldType, + index: Int & FieldIndex[FieldType]) ?=> ResultType) : ResultType = inline erasedValue[FieldsType] match diff --git a/src/core/wisteria.SumDerivationMethods.scala b/src/core/wisteria.SumDerivationMethods.scala index dac2502..fcf1a27 100644 --- a/src/core/wisteria.SumDerivationMethods.scala +++ b/src/core/wisteria.SumDerivationMethods.scala @@ -38,8 +38,8 @@ trait SumDerivationMethods[TypeclassType[_]]: case _ => false protected transparent inline def complement[DerivationType, VariantType](sum: DerivationType) - (using variantIndex: Int & VariantIndex[VariantType], - reflection: SumReflection[DerivationType]) + (using variantIndex: Int & VariantIndex[VariantType], + reflection: SumReflection[DerivationType]) : Optional[VariantType] = type Labels = reflection.MirroredElemLabels @@ -51,20 +51,20 @@ trait SumDerivationMethods[TypeclassType[_]]: if index == variantIndex then field.asInstanceOf[VariantType] else Unset protected inline def variantLabels[DerivationType] - (using reflection: SumReflection[DerivationType]) + (using reflection: SumReflection[DerivationType]) : List[Text] = constValueTuple[reflection.MirroredElemLabels].toList.map(_.toString.tt) protected transparent inline def delegate[DerivationType](label: Text) - (using reflection: SumReflection[DerivationType], requirement: ContextRequirement) - [ResultType] - (inline lambda: [VariantType <: DerivationType] => - requirement.Optionality[TypeclassType[VariantType]] => - (context: requirement.Optionality[TypeclassType[VariantType]], - label: Text, - index: Int & VariantIndex[VariantType]) ?=> - ResultType) + (using reflection: SumReflection[DerivationType], requirement: ContextRequirement) + [ResultType] + (inline lambda: [VariantType <: DerivationType] => + requirement.Optionality[TypeclassType[VariantType]] => + (context: requirement.Optionality[TypeclassType[VariantType]], + label: Text, + index: Int & VariantIndex[VariantType]) ?=> + ResultType) : ResultType = type Labels = reflection.MirroredElemLabels @@ -79,14 +79,14 @@ trait SumDerivationMethods[TypeclassType[_]]: .vouch(using Unsafe) protected transparent inline def variant[DerivationType](sum: DerivationType) - (using reflection: SumReflection[DerivationType], requirement: ContextRequirement) - [ResultType] - (inline lambda: [VariantType <: DerivationType] => - VariantType => - (context: requirement.Optionality[TypeclassType[VariantType]], - label: Text, - index: Int & VariantIndex[VariantType]) ?=> - ResultType) + (using reflection: SumReflection[DerivationType], requirement: ContextRequirement) + [ResultType] + (inline lambda: [VariantType <: DerivationType] => + VariantType => + (context: requirement.Optionality[TypeclassType[VariantType]], + label: Text, + index: Int & VariantIndex[VariantType]) ?=> + ResultType) : ResultType = type Labels = reflection.MirroredElemLabels @@ -99,16 +99,16 @@ trait SumDerivationMethods[TypeclassType[_]]: .vouch(using Unsafe) private transparent inline def fold[DerivationType, VariantsType <: Tuple, LabelsType <: Tuple] - (inline inputLabel: Text, size: Int, index: Int, fallible: Boolean) - (using reflection: SumReflection[DerivationType], requirement: ContextRequirement) - (inline predicate: (label: Text, index: Int & VariantIndex[DerivationType]) ?=> Boolean) - [ResultType] - (inline lambda: [VariantType <: DerivationType] => - requirement.Optionality[TypeclassType[VariantType]] => - (context: requirement.Optionality[TypeclassType[VariantType]], - label: Text, - index: Int & VariantIndex[VariantType]) ?=> - ResultType) + (inline inputLabel: Text, size: Int, index: Int, fallible: Boolean) + (using reflection: SumReflection[DerivationType], requirement: ContextRequirement) + (inline predicate: (label: Text, index: Int & VariantIndex[DerivationType]) ?=> Boolean) + [ResultType] + (inline lambda: [VariantType <: DerivationType] => + requirement.Optionality[TypeclassType[VariantType]] => + (context: requirement.Optionality[TypeclassType[VariantType]], + label: Text, + index: Int & VariantIndex[VariantType]) ?=> + ResultType) : Optional[ResultType] = inline erasedValue[VariantsType] match @@ -138,16 +138,16 @@ trait SumDerivationMethods[TypeclassType[_]]: else throw Panic(m"Should be unreachable") private transparent inline def fold[DerivationType, VariantsType <: Tuple, LabelsType <: Tuple] - (inline sum: DerivationType, size: Int, index: Int, fallible: Boolean) - (using reflection: SumReflection[DerivationType], requirement: ContextRequirement) - (inline predicate: (label: Text, index: Int & VariantIndex[DerivationType]) ?=> Boolean) - [ResultType] - (inline lambda: [VariantType <: DerivationType] => - VariantType => - (context: requirement.Optionality[TypeclassType[VariantType]], - label: Text, - index: Int & VariantIndex[VariantType]) ?=> - ResultType) + (inline sum: DerivationType, size: Int, index: Int, fallible: Boolean) + (using reflection: SumReflection[DerivationType], requirement: ContextRequirement) + (inline predicate: (label: Text, index: Int & VariantIndex[DerivationType]) ?=> Boolean) + [ResultType] + (inline lambda: [VariantType <: DerivationType] => + VariantType => + (context: requirement.Optionality[TypeclassType[VariantType]], + label: Text, + index: Int & VariantIndex[VariantType]) ?=> + ResultType) : Optional[ResultType] = inline erasedValue[VariantsType] match diff --git a/src/core/wisteria.VariantError.scala b/src/core/wisteria.VariantError.scala index f720c4c..d9cde0c 100644 --- a/src/core/wisteria.VariantError.scala +++ b/src/core/wisteria.VariantError.scala @@ -25,7 +25,7 @@ import scala.compiletime.* object VariantError: inline def apply[DerivationType](inputLabel: Text) - (using reflection: SumReflection[DerivationType], diagnostics: Diagnostics) + (using reflection: SumReflection[DerivationType], diagnostics: Diagnostics) : VariantError = val variants = constValueTuple[reflection.MirroredElemLabels].toList.map(_.toString.tt) @@ -35,4 +35,4 @@ object VariantError: case class VariantError(inputLabel: Text, sum: Text, validVariants: List[Text])(using Diagnostics) extends Error - (m"""the specified variant ($inputLabel) is not one of the valid variants (${validVariants.mkString(", ").tt}) of sum type $sum""") + (m"""the specified variant ($inputLabel) is not one of the valid variants (${validVariants.mkString(", ").tt}) of sum type $sum""")