From 2369fee2b110618fd74b8df5370136625863e4f6 Mon Sep 17 00:00:00 2001 From: Erik Erlandson Date: Thu, 18 Apr 2024 13:37:46 -0700 Subject: [PATCH] scalafmt --- .../coulomb/conversion/coefficient.scala | 35 +++++++++----- .../scala/coulomb/conversion/deltaunit.scala | 31 ++++++------ .../scala/coulomb/conversion/offset.scala | 23 ++++----- .../main/scala/coulomb/conversion/unit.scala | 47 ++++++++++++------- .../main/scala/coulomb/infra/typeexpr.scala | 6 ++- core/src/main/scala/coulomb/policy.scala | 2 +- core/src/main/scala/coulomb/quantity.scala | 6 +-- core/src/main/scala/coulomb/syntax.scala | 4 +- core/src/test/scala/coulomb/quantity.scala | 10 ++-- .../test/scala/coulomb/testing/units.scala | 4 +- pureconfig/src/main/scala/coulomb/io.scala | 8 +++- units/src/main/scala/coulomb/units/mksa.scala | 8 ++-- .../scala/coulomb/units/temperature.scala | 3 +- units/src/main/scala/coulomb/units/us.scala | 3 +- units/src/test/scala/coulomb/spiretemps.scala | 3 +- 15 files changed, 115 insertions(+), 78 deletions(-) diff --git a/core/src/main/scala/coulomb/conversion/coefficient.scala b/core/src/main/scala/coulomb/conversion/coefficient.scala index 2fd708edb..1ac4bd0d4 100644 --- a/core/src/main/scala/coulomb/conversion/coefficient.scala +++ b/core/src/main/scala/coulomb/conversion/coefficient.scala @@ -19,7 +19,7 @@ package coulomb.conversion import scala.annotation.implicitNotFound @implicitNotFound( - "No coefficient could be derived for value type ${V}, unit types ${UF} => ${UT}" + "No coefficient could be derived for value type ${V}, unit types ${UF} => ${UT}" ) class Coefficient[V, UF, UT](val value: V) @@ -53,22 +53,35 @@ object Coefficient: case _: java.lang.Double => coefficientDoubleJ[UF, UT].asInstanceOf[V] case _ => - summonInline[Coefficient[V, UF, UT]].value + summonInline[Coefficient[V, UF, UT]].value inline given g_Coefficient[V, UF, UT]: Coefficient[V, UF, UT] = inline erasedValue[V] match - case _: Float => - new Coefficient[V, UF, UT](coefficientFloat[UF, UT].asInstanceOf[V]) - case _: Double => - new Coefficient[V, UF, UT](coefficientDouble[UF, UT].asInstanceOf[V]) + case _: Float => + new Coefficient[V, UF, UT]( + coefficientFloat[UF, UT].asInstanceOf[V] + ) + case _: Double => + new Coefficient[V, UF, UT]( + coefficientDouble[UF, UT].asInstanceOf[V] + ) case _: BigDecimal => - new Coefficient[V, UF, UT](coefficientBigDecimal[UF, UT].asInstanceOf[V]) + new Coefficient[V, UF, UT]( + coefficientBigDecimal[UF, UT].asInstanceOf[V] + ) case _: Rational => - new Coefficient[V, UF, UT](coefficientRational[UF, UT].asInstanceOf[V]) + new Coefficient[V, UF, UT]( + coefficientRational[UF, UT].asInstanceOf[V] + ) case _: java.lang.Float => - new Coefficient[V, UF, UT](coefficientFloatJ[UF, UT].asInstanceOf[V]) + new Coefficient[V, UF, UT]( + coefficientFloatJ[UF, UT].asInstanceOf[V] + ) case _: java.lang.Double => - new Coefficient[V, UF, UT](coefficientDoubleJ[UF, UT].asInstanceOf[V]) + new Coefficient[V, UF, UT]( + coefficientDoubleJ[UF, UT].asInstanceOf[V] + ) case _ => - val (_, vc) = summonAll[(Fractional[V], ValueConversion[Rational, V])] + val (_, vc) = + summonAll[(Fractional[V], ValueConversion[Rational, V])] new Coefficient[V, UF, UT](vc(coefficientRational[UF, UT])) diff --git a/core/src/main/scala/coulomb/conversion/deltaunit.scala b/core/src/main/scala/coulomb/conversion/deltaunit.scala index 2ff891f54..9123815c6 100644 --- a/core/src/main/scala/coulomb/conversion/deltaunit.scala +++ b/core/src/main/scala/coulomb/conversion/deltaunit.scala @@ -49,21 +49,22 @@ object DeltaUnitConversion: inline def apply[V, B, UF, UT](v: V): V = if (typeexpr.teq[UF, UT]) v - else inline erasedValue[V] match - case _: Float => - applyShim[V, B, UF, UT](v)(using summonInline[Rng[V]]) - case _: Double => - applyShim[V, B, UF, UT](v)(using summonInline[Rng[V]]) - case _: BigDecimal => - applyShim[V, B, UF, UT](v)(using summonInline[Rng[V]]) - case _: Rational => - applyShim[V, B, UF, UT](v)(using summonInline[Rng[V]]) - case _: java.lang.Float => - applyShim[V, B, UF, UT](v)(using summonInline[Rng[V]]) - case _: java.lang.Double => - applyShim[V, B, UF, UT](v)(using summonInline[Rng[V]]) - case _ => - summonInline[DeltaUnitConversion[V, B, UF, UT]](v) + else + inline erasedValue[V] match + case _: Float => + applyShim[V, B, UF, UT](v)(using summonInline[Rng[V]]) + case _: Double => + applyShim[V, B, UF, UT](v)(using summonInline[Rng[V]]) + case _: BigDecimal => + applyShim[V, B, UF, UT](v)(using summonInline[Rng[V]]) + case _: Rational => + applyShim[V, B, UF, UT](v)(using summonInline[Rng[V]]) + case _: java.lang.Float => + applyShim[V, B, UF, UT](v)(using summonInline[Rng[V]]) + case _: java.lang.Double => + applyShim[V, B, UF, UT](v)(using summonInline[Rng[V]]) + case _ => + summonInline[DeltaUnitConversion[V, B, UF, UT]](v) inline given g_DeltaUnitConversion[V, B, UF, UT](using Rng[V] diff --git a/core/src/main/scala/coulomb/conversion/offset.scala b/core/src/main/scala/coulomb/conversion/offset.scala index a0de0086f..fd4e155ad 100644 --- a/core/src/main/scala/coulomb/conversion/offset.scala +++ b/core/src/main/scala/coulomb/conversion/offset.scala @@ -19,7 +19,7 @@ package coulomb.conversion import scala.annotation.implicitNotFound @implicitNotFound( - "No offset could be derived for Offset[${V}, ${U}, ${B}]" + "No offset could be derived for Offset[${V}, ${U}, ${B}]" ) class Offset[V, U, B](val value: V) @@ -32,29 +32,30 @@ object Offset: inline def apply[V, U, B]: V = inline erasedValue[V] match - case _: Float => deltaOffsetFloat[U, B].asInstanceOf[V] - case _: Double => deltaOffsetDouble[U, B].asInstanceOf[V] - case _: BigDecimal => deltaOffsetBigDecimal[U, B].asInstanceOf[V] - case _: Rational => deltaOffsetRational[U, B].asInstanceOf[V] - case _: java.lang.Float => deltaOffsetFloatJ[U, B].asInstanceOf[V] + case _: Float => deltaOffsetFloat[U, B].asInstanceOf[V] + case _: Double => deltaOffsetDouble[U, B].asInstanceOf[V] + case _: BigDecimal => deltaOffsetBigDecimal[U, B].asInstanceOf[V] + case _: Rational => deltaOffsetRational[U, B].asInstanceOf[V] + case _: java.lang.Float => deltaOffsetFloatJ[U, B].asInstanceOf[V] case _: java.lang.Double => deltaOffsetDoubleJ[U, B].asInstanceOf[V] case _ => summonInline[Offset[V, U, B]].value inline given g_Offset[V, U, B]: Offset[V, U, B] = inline erasedValue[V] match - case _: Float => + case _: Float => new Offset[V, U, B](deltaOffsetFloat[U, B].asInstanceOf[V]) - case _: Double => + case _: Double => new Offset[V, U, B](deltaOffsetDouble[U, B].asInstanceOf[V]) case _: BigDecimal => new Offset[V, U, B](deltaOffsetBigDecimal[U, B].asInstanceOf[V]) case _: Rational => new Offset[V, U, B](deltaOffsetRational[U, B].asInstanceOf[V]) - case _: java.lang.Float => + case _: java.lang.Float => new Offset[V, U, B](deltaOffsetFloatJ[U, B].asInstanceOf[V]) - case _: java.lang.Double => + case _: java.lang.Double => new Offset[V, U, B](deltaOffsetDoubleJ[U, B].asInstanceOf[V]) case _ => - val (_, vc) = summonAll[(Fractional[V], ValueConversion[Rational, V])] + val (_, vc) = + summonAll[(Fractional[V], ValueConversion[Rational, V])] new Offset[V, U, B](vc(deltaOffsetRational[U, B])) diff --git a/core/src/main/scala/coulomb/conversion/unit.scala b/core/src/main/scala/coulomb/conversion/unit.scala index ffbd136e0..3932f7ac3 100644 --- a/core/src/main/scala/coulomb/conversion/unit.scala +++ b/core/src/main/scala/coulomb/conversion/unit.scala @@ -40,23 +40,36 @@ object UnitConversion: inline def apply[V, UF, UT](v: V): V = if (typeexpr.teq[UF, UT]) v - else inline erasedValue[V] match - // This enumerates all the cases where I have an inline macro for the coefficient - case _: Float => - applyShim[V, UF, UT](v)(using summonInline[MultiplicativeSemigroup[V]]) - case _: Double => - applyShim[V, UF, UT](v)(using summonInline[MultiplicativeSemigroup[V]]) - case _: BigDecimal => - applyShim[V, UF, UT](v)(using summonInline[MultiplicativeSemigroup[V]]) - case _: Rational => - applyShim[V, UF, UT](v)(using summonInline[MultiplicativeSemigroup[V]]) - case _: java.lang.Float => - applyShim[V, UF, UT](v)(using summonInline[MultiplicativeSemigroup[V]]) - case _: java.lang.Double => - applyShim[V, UF, UT](v)(using summonInline[MultiplicativeSemigroup[V]]) - case _ => - // otherwise summon a unit conversion from context - summonInline[UnitConversion[V, UF, UT]](v) + else + inline erasedValue[V] match + // This enumerates all the cases where I have an inline macro for the coefficient + case _: Float => + applyShim[V, UF, UT](v)(using + summonInline[MultiplicativeSemigroup[V]] + ) + case _: Double => + applyShim[V, UF, UT](v)(using + summonInline[MultiplicativeSemigroup[V]] + ) + case _: BigDecimal => + applyShim[V, UF, UT](v)(using + summonInline[MultiplicativeSemigroup[V]] + ) + case _: Rational => + applyShim[V, UF, UT](v)(using + summonInline[MultiplicativeSemigroup[V]] + ) + case _: java.lang.Float => + applyShim[V, UF, UT](v)(using + summonInline[MultiplicativeSemigroup[V]] + ) + case _: java.lang.Double => + applyShim[V, UF, UT](v)(using + summonInline[MultiplicativeSemigroup[V]] + ) + case _ => + // otherwise summon a unit conversion from context + summonInline[UnitConversion[V, UF, UT]](v) inline given g_UnitConversion[V, UF, UT](using MultiplicativeSemigroup[V] diff --git a/core/src/main/scala/coulomb/infra/typeexpr.scala b/core/src/main/scala/coulomb/infra/typeexpr.scala index 549e61e4c..f4a576571 100644 --- a/core/src/main/scala/coulomb/infra/typeexpr.scala +++ b/core/src/main/scala/coulomb/infra/typeexpr.scala @@ -45,7 +45,11 @@ object typeexpr: inline def teq[T1, T2]: Boolean = ${ teqImpl[T1, T2] } - private def teqImpl[T1, T2](using Quotes, Type[T1], Type[T2]): Expr[Boolean] = + private def teqImpl[T1, T2](using + Quotes, + Type[T1], + Type[T2] + ): Expr[Boolean] = import quotes.reflect.* if (TypeRepr.of[T1] =:= TypeRepr.of[T2]) '{ true } diff --git a/core/src/main/scala/coulomb/policy.scala b/core/src/main/scala/coulomb/policy.scala index 22a57a2b1..3e8ab48c6 100644 --- a/core/src/main/scala/coulomb/policy.scala +++ b/core/src/main/scala/coulomb/policy.scala @@ -29,7 +29,7 @@ package coulomb.policy * }}} */ object standard: - //export coulomb.conversion.standard.scala.given + // export coulomb.conversion.standard.scala.given export coulomb.cats.all.given export coulomb.conversion.ops.policy.given diff --git a/core/src/main/scala/coulomb/quantity.scala b/core/src/main/scala/coulomb/quantity.scala index c02cf9e7a..50049e005 100644 --- a/core/src/main/scala/coulomb/quantity.scala +++ b/core/src/main/scala/coulomb/quantity.scala @@ -16,7 +16,6 @@ package coulomb - /** * Represents the product of two unit expressions * @tparam L @@ -98,7 +97,7 @@ object Quantity: object Applier: given g_Applier[U]: Applier[U] = new Applier[U] - extension[V](v: V) + extension [V](v: V) /** * Lift a raw value into a unit quantity * @tparam U @@ -111,7 +110,7 @@ object Quantity: */ inline def withUnit[U]: Quantity[V, U] = v - extension[V, U, Q[V, U] <: Quantity[V, U]](q: Q[V, U]) + extension [V, U, Q[V, U] <: Quantity[V, U]](q: Q[V, U]) /** * extract the raw value of a unit quantity * @return @@ -545,4 +544,3 @@ object foo: import coulomb.conversion.ops.policy.given import coulomb.policy.algebras.given val x = 1d.withUnit[1] + 1d.withUnit[1000] - diff --git a/core/src/main/scala/coulomb/syntax.scala b/core/src/main/scala/coulomb/syntax.scala index 41b479ee2..5df4dad2f 100644 --- a/core/src/main/scala/coulomb/syntax.scala +++ b/core/src/main/scala/coulomb/syntax.scala @@ -28,14 +28,14 @@ export coulomb.DeltaQuantity.withDeltaUnit // there are three tricks I applied to get scalar factors to work. // 1. I use the signature: // extension[V, U, Q[V, U] <: Quantity[V, U]](q: Q[V, U]) -// for the Quantity methods, which helps the type system to +// for the Quantity methods, which helps the type system to // distinguish from the left-factor overloadings defined in this file. // 2. I define the right-factor overloadings in the Quantity extension, // because defining them separately here is confusing the compiler // 3. I curry `using alg: ...` first below, which allows the compiler to // pick the correct typeclass. -extension[V](v: V) +extension [V](v: V) inline def *[U](using alg: MultiplicativeSemigroup[V] )(q: Quantity[V, U]): Quantity[V, U] = diff --git a/core/src/test/scala/coulomb/quantity.scala b/core/src/test/scala/coulomb/quantity.scala index 4f1cedf28..01d94eea1 100644 --- a/core/src/test/scala/coulomb/quantity.scala +++ b/core/src/test/scala/coulomb/quantity.scala @@ -441,13 +441,13 @@ class QuantitySuite extends CoulombSuite: } test("scalar factors") { - val q = 2d.withUnit[Meter] + val q = 2d.withUnit[Meter] - (2d * q).assertQ[Double, Meter](4) - (2d / q).assertQ[Double, 1 / Meter](1) + (2d * q).assertQ[Double, Meter](4) + (2d / q).assertQ[Double, 1 / Meter](1) - (q * 2d).assertQ[Double, Meter](4) - (q / 2d).assertQ[Double, Meter](1) + (q * 2d).assertQ[Double, Meter](4) + (q / 2d).assertQ[Double, Meter](1) } test("cats Eq, Ord, Hash") { diff --git a/core/src/test/scala/coulomb/testing/units.scala b/core/src/test/scala/coulomb/testing/units.scala index ace730c49..eba459df7 100644 --- a/core/src/test/scala/coulomb/testing/units.scala +++ b/core/src/test/scala/coulomb/testing/units.scala @@ -68,8 +68,8 @@ final type Kelvin given unit_Kelvin: BaseUnit[Kelvin, "kelvin", "K"] = BaseUnit() final type Celsius -given unit_Celsius - : DeltaUnit[Celsius, Kelvin, 27315 / 100, "celsius", "°C"] = DeltaUnit() +given unit_Celsius: DeltaUnit[Celsius, Kelvin, 27315 / 100, "celsius", "°C"] = + DeltaUnit() final type Fahrenheit given unit_Fahrenheit diff --git a/pureconfig/src/main/scala/coulomb/io.scala b/pureconfig/src/main/scala/coulomb/io.scala index 8af3958ce..2908fd793 100644 --- a/pureconfig/src/main/scala/coulomb/io.scala +++ b/pureconfig/src/main/scala/coulomb/io.scala @@ -214,7 +214,13 @@ object quantity: // (or equivalent) to the unit we are loading from inline given ctx_Quantity_Reader_NoVC[V, U](using nocv: NotGiven[ - GivenAll[(Fractional[V], ValueConversion[Rational, V], MultiplicativeSemigroup[V])] + GivenAll[ + ( + Fractional[V], + ValueConversion[Rational, V], + MultiplicativeSemigroup[V] + ) + ] ], crq: ConfigReader[RuntimeQuantity[V]], crt: CoefficientRuntime diff --git a/units/src/main/scala/coulomb/units/mksa.scala b/units/src/main/scala/coulomb/units/mksa.scala index ada95209a..0e75ca999 100644 --- a/units/src/main/scala/coulomb/units/mksa.scala +++ b/units/src/main/scala/coulomb/units/mksa.scala @@ -34,8 +34,8 @@ object mksa: /** Unit of electric charge */ final type Coulomb - given unit_Coulomb - : DerivedUnit[Coulomb, Ampere * Second, "coulomb", "C"] = DerivedUnit() + given unit_Coulomb: DerivedUnit[Coulomb, Ampere * Second, "coulomb", "C"] = + DerivedUnit() /** Unit of electric voltage */ final type Volt @@ -64,8 +64,8 @@ object mksa: /** Unit of magnetic flux density */ final type Tesla - given unit_Tesla - : DerivedUnit[Tesla, Weber / (Meter ^ 2), "tesla", "T"] = DerivedUnit() + given unit_Tesla: DerivedUnit[Tesla, Weber / (Meter ^ 2), "tesla", "T"] = + DerivedUnit() /** Unit of electric inductance */ final type Henry diff --git a/units/src/main/scala/coulomb/units/temperature.scala b/units/src/main/scala/coulomb/units/temperature.scala index 0a803d039..98a5bcec5 100644 --- a/units/src/main/scala/coulomb/units/temperature.scala +++ b/units/src/main/scala/coulomb/units/temperature.scala @@ -86,4 +86,5 @@ object temperature: * val freeze = (0.0).withTemperature[Celsius] * }}} */ - inline def withTemperature[U]: Temperature[V, U] = v.withDeltaUnit[U, Kelvin] + inline def withTemperature[U]: Temperature[V, U] = + v.withDeltaUnit[U, Kelvin] diff --git a/units/src/main/scala/coulomb/units/us.scala b/units/src/main/scala/coulomb/units/us.scala index c99d10aad..f60e1ec63 100644 --- a/units/src/main/scala/coulomb/units/us.scala +++ b/units/src/main/scala/coulomb/units/us.scala @@ -44,8 +44,7 @@ object us: * - https://en.wikipedia.org/wiki/International_yard_and_pound */ final type Yard - given unit_Yard - : DerivedUnit[Yard, (9144 / 10000) * Meter, "yard", "yd"] = + given unit_Yard: DerivedUnit[Yard, (9144 / 10000) * Meter, "yard", "yd"] = DerivedUnit() /** diff --git a/units/src/test/scala/coulomb/spiretemps.scala b/units/src/test/scala/coulomb/spiretemps.scala index 1c381e057..aa03d32c3 100644 --- a/units/src/test/scala/coulomb/spiretemps.scala +++ b/units/src/test/scala/coulomb/spiretemps.scala @@ -82,7 +82,8 @@ class SpireTemperatureSuite extends CoulombSuite: test("quantity subtraction") { import coulomb.policy.standard.given - (BigDecimal(100).withTemperature[Celsius] - BigDecimal(90).withUnit[Fahrenheit]) + (BigDecimal(100).withTemperature[Celsius] - BigDecimal(90) + .withUnit[Fahrenheit]) .assertDQD[BigDecimal, Celsius](50) }