Skip to content

Commit

Permalink
redo consumption types
Browse files Browse the repository at this point in the history
  • Loading branch information
ThibClnt committed Jan 19, 2024
1 parent 55362b2 commit 533dd4d
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/main/scala/Types.scala
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,38 @@ object Types {
implicit val GWOrdering: Ordering[GW] = (x: GW, y: GW) => x.toFloat compare y.toFloat
}

object Consumption {
type kWh = Float
type MWh = Float
type GWh = Float

object kWh {
def apply(value: Float): kWh = value
def toMWh(value: kWh): MWh = value / 1000
def toGWh(value: kWh): GWh = value / 1000000
}

object MWh {
def apply(value: Float): MWh = value
def tokWh(value: MWh): kWh = value * 1000
def toGWh(value: MWh): GWh = value / 1000
}

object GWh {
def apply(value: Float): GWh = value
def tokWh(value: GWh): kWh = value * 1000000
def toMWh(value: GWh): MWh = value * 1000
}

given Conversion[Float, kWh] = kWh(_)
given Conversion[Float, MWh] = MWh(_)
given Conversion[Float, GWh] = GWh(_)

implicit val kWhOrdering: Ordering[kWh] = (x: kWh, y: kWh) => x.toFloat compare y.toFloat
implicit val MWhOrdering: Ordering[MWh] = (x: MWh, y: MWh) => x.toFloat compare y.toFloat
implicit val GWhOrdering: Ordering[GWh] = (x: GWh, y: GWh) => x.toFloat compare y.toFloat
}

object Temperature {
type Celsius = Float

Expand Down

0 comments on commit 533dd4d

Please sign in to comment.