Skip to content

Commit

Permalink
Tweak coding style
Browse files Browse the repository at this point in the history
  • Loading branch information
propensive committed Feb 27, 2024
1 parent ea29894 commit d52d32e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 28 deletions.
46 changes: 23 additions & 23 deletions src/core/cardinality.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand All @@ -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)}

Expand All @@ -73,57 +70,60 @@ 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")
infix def + (right: Double): Double = left + right

@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")
infix def * (right: Double): Double = left*right

@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")
infix def - (right: Double): Double = left - right

@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")
Expand Down
8 changes: 3 additions & 5 deletions src/core/numbermacros.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d52d32e

Please sign in to comment.