From d52d32e93f84e4e4753baf481b473790568bcd52 Mon Sep 17 00:00:00 2001 From: Jon Pretty Date: Tue, 27 Feb 2024 09:33:20 +0100 Subject: [PATCH] Tweak coding style --- src/core/cardinality.scala | 46 ++++++++++++++++++------------------- src/core/numbermacros.scala | 8 +++---- 2 files changed, 26 insertions(+), 28 deletions(-) diff --git a/src/core/cardinality.scala b/src/core/cardinality.scala index 73ac421..a938af6 100644 --- a/src/core/cardinality.scala +++ b/src/core/cardinality.scala @@ -42,18 +42,15 @@ object NumericRange: @targetName("Range") opaque infix type ~[MinValueType <: Double, MaxValueType <: Double] = Double - def apply - [MinValueType <: Double, MaxValueType <: Double] - (value: Double) - : MinValueType ~ MaxValueType = + def apply[MinValueType <: Double, MaxValueType <: Double](value: Double): MinValueType ~ MaxValueType = value @targetName("Range") object `~`: - given comparable - [MinValueType <: Double & Singleton, MaxValueType <: Double & Singleton] + given comparable[MinValueType <: Double & Singleton, MaxValueType <: Double & Singleton] (using min: ValueOf[MinValueType], max: ValueOf[MaxValueType]) - : TypeTest[Double, MinValueType ~ MaxValueType] = + : TypeTest[Double, MinValueType ~ MaxValueType] = + value => if value >= min.value && value <= max.value then Some(value.asInstanceOf[(MinValueType ~ MaxValueType) & value.type]) @@ -64,7 +61,7 @@ object NumericRange: def fromDigits(digits: String): Double = apply(digits.toDouble) given cardinality[MinValueType <: Double, MaxValueType <: Double] - : RangeParser[MinValueType, MaxValueType] with + : RangeParser[MinValueType, MaxValueType] with override inline def fromDigits(digits: String): MinValueType ~ MaxValueType = ${Cardinality('digits)} @@ -73,12 +70,11 @@ object NumericRange: @targetName("add") infix def + [RightMinType <: Double, RightMaxType <: Double](right: RightMinType ~ RightMaxType) - : (LeftMinType + RightMinType) ~ (LeftMaxType + RightMaxType) = + : (LeftMinType + RightMinType) ~ (LeftMaxType + RightMaxType) = left + right @targetName("add2") - infix def + [E <: Double & Singleton](right: E) - : (LeftMinType + right.type) ~ (LeftMaxType + right.type) = + infix def + [E <: Double & Singleton](right: E): (LeftMinType + right.type) ~ (LeftMaxType + right.type) = left + right @targetName("add3") @@ -86,14 +82,16 @@ object NumericRange: @targetName("times") infix def * [RightMinType <: Double, RightMaxType <: Double](right: RightMinType ~ RightMaxType) - : (Min4[LeftMinType*RightMinType, LeftMinType*RightMaxType, LeftMaxType*RightMaxType, - LeftMaxType*RightMinType]) ~ (Max4[LeftMinType*RightMinType, LeftMinType*RightMaxType, - LeftMaxType*RightMaxType, LeftMaxType*RightMinType]) = + : (Min4[LeftMinType*RightMinType, LeftMinType*RightMaxType, LeftMaxType*RightMaxType, + LeftMaxType*RightMinType]) ~ (Max4[LeftMinType*RightMinType, LeftMinType*RightMaxType, + LeftMaxType*RightMaxType, LeftMaxType*RightMinType]) = + left*right @targetName("times2") infix def * [E <: Double & Singleton](right: E) - : Min[LeftMinType*E, LeftMaxType*E] ~ Max[LeftMinType*E, LeftMaxType*E] = + : Min[LeftMinType*E, LeftMaxType*E] ~ Max[LeftMinType*E, LeftMaxType*E] = + left*right @targetName("times3") @@ -101,13 +99,14 @@ object NumericRange: @targetName("minus") infix def - [RightMinType <: Double, RightMaxType <: Double](right: RightMinType ~ RightMaxType) - : Min[LeftMinType - RightMinType, LeftMinType - RightMaxType] ~ Max[LeftMaxType - - RightMinType, LeftMaxType - RightMaxType] = + : Min[LeftMinType - RightMinType, LeftMinType - RightMaxType] ~ Max[LeftMaxType - + RightMinType, LeftMaxType - RightMaxType] = left - right @targetName("minus2") infix def - [E <: Double & Singleton](right: E) - : Min[LeftMinType - E, LeftMaxType - E] ~ Max[LeftMinType - E, LeftMaxType - E] = + : Min[LeftMinType - E, LeftMaxType - E] ~ Max[LeftMinType - E, LeftMaxType - E] = + left - right @targetName("minus3") @@ -115,15 +114,16 @@ object NumericRange: @targetName("divide") infix def / [E <: Double & Singleton](right: E) - : Min[LeftMinType/E, LeftMaxType/E] ~ Max[LeftMinType/E, LeftMaxType/E] = + : Min[LeftMinType/E, LeftMaxType/E] ~ Max[LeftMinType/E, LeftMaxType/E] = + left/right @targetName("divide2") infix def / [RightMinType <: Double, RightMaxType <: Double](right: RightMinType ~ RightMaxType) - : Asym[RightMinType*RightMaxType, Min4[LeftMinType/RightMinType, LeftMaxType/RightMinType, - LeftMinType/RightMaxType, LeftMaxType/RightMaxType], -1.0/0.0] ~ Asym[ - RightMinType*RightMaxType, Max4[LeftMinType/RightMinType, LeftMaxType/RightMinType, - LeftMinType/RightMaxType, LeftMaxType/RightMaxType], 1.0/0.0] = + : Asym[RightMinType*RightMaxType, Min4[LeftMinType/RightMinType, LeftMaxType/RightMinType, + LeftMinType/RightMaxType, LeftMaxType/RightMaxType], -1.0/0.0] ~ Asym[ + RightMinType*RightMaxType, Max4[LeftMinType/RightMinType, LeftMaxType/RightMinType, + LeftMinType/RightMaxType, LeftMaxType/RightMaxType], 1.0/0.0] = left/right @targetName("divide3") diff --git a/src/core/numbermacros.scala b/src/core/numbermacros.scala index dc4787c..8567b4b 100644 --- a/src/core/numbermacros.scala +++ b/src/core/numbermacros.scala @@ -24,11 +24,9 @@ import scala.compiletime.* object Cardinality: given Realm = realm"cardinality" - def apply - [LeftDoubleType <: Double: Type, RightDoubleType <: Double: Type] - (digits: Expr[String]) - (using Quotes) - : Expr[LeftDoubleType ~ RightDoubleType] = + def apply[LeftDoubleType <: Double: Type, RightDoubleType <: Double: Type](digits: Expr[String])(using Quotes) + : Expr[LeftDoubleType ~ RightDoubleType] = + import quotes.reflect.* digits.value match