Skip to content

Commit

Permalink
neg with SAM/lambda
Browse files Browse the repository at this point in the history
  • Loading branch information
erikerlandson committed Apr 5, 2022
1 parent cd3e7cf commit f485d2b
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 15 deletions.
3 changes: 1 addition & 2 deletions core/src/main/scala/coulomb/ops/ops.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ import scala.annotation.implicitNotFound
import coulomb.*

@implicitNotFound("Negation not defined in scope for Quantity[${V}, ${U}]")
abstract class Neg[V, U]:
def apply(q: Quantity[V, U]): Quantity[V, U]
abstract class Neg[V, U] extends (Quantity[V, U] => Quantity[V, U])

@implicitNotFound("Addition not defined in scope for Quantity[${VL}, ${UL}] and Quantity[${VR}, ${UR}]")
abstract class Add[VL, UL, VR, UR]:
Expand Down
9 changes: 2 additions & 7 deletions core/src/main/scala/coulomb/ops/standard/neg.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,5 @@ object neg:
import coulomb.{Quantity, withUnit}
import coulomb.ops.Neg

inline given ctx_quantity_neg[V, U](using alg: AdditiveGroup[V]): Neg[V, U] =
new infra.NegNC[V, U](alg)

object infra:
class NegNC[V, U](alg: AdditiveGroup[V]) extends Neg[V, U]:
def apply(q: Quantity[V, U]): Quantity[V, U] =
alg.negate(q.value).withUnit[U]
given ctx_quantity_neg[V, U](using alg: AdditiveGroup[V]): Neg[V, U] =
(q: Quantity[V, U]) => alg.negate(q.value).withUnit[U]
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,8 @@ import coulomb.ops.standard.named.*
import coulomb.conversion.coefficients.*

object double:
inline given ctx_quantity_neg_Double[U]: Neg[Double, U] =
new Neg[Double, U]:
def apply(q: Quantity[Double, U]): Quantity[Double, U] = (-(q.value)).withUnit[U]
given ctx_quantity_neg_Double[U]: Neg[Double, U] =
(q: Quantity[Double, U]) => (-(q.value)).withUnit[U]

transparent inline given ctx_add_Double_1U[U]: Add[Double, U, Double, U] =
new AddNC((ql: Quantity[Double, U], qr: Quantity[Double, U]) => (ql.value + qr.value).withUnit[U])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,8 @@ import coulomb.ops.standard.named.*
import coulomb.conversion.coefficients.*

object float:
inline given ctx_quantity_neg_Float[U]: Neg[Float, U] =
new Neg[Float, U]:
def apply(q: Quantity[Float, U]): Quantity[Float, U] = (-(q.value)).withUnit[U]
given ctx_quantity_neg_Float[U]: Neg[Float, U] =
(q: Quantity[Float, U]) => (-(q.value)).withUnit[U]

transparent inline given ctx_add_Float_1U[U]: Add[Float, U, Float, U] =
new AddNC((ql: Quantity[Float, U], qr: Quantity[Float, U]) => (ql.value + qr.value).withUnit[U])
Expand Down

0 comments on commit f485d2b

Please sign in to comment.