Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save bartbuijse/c65dafd6074595cd137abef309e4f741 to your computer and use it in GitHub Desktop.
Save bartbuijse/c65dafd6074595cd137abef309e4f741 to your computer and use it in GitHub Desktop.
object Playground extends App {
import squants._
import squants.energy._
def parse(s: String, i: Int): Option[Quantity[_]] =
Seq(Energy, EnergyDensity, Power)
.foldLeft(Option.empty[Quantity[_]]) {
case (None, dimension) => dimension.parseTuple((i,s)).toOption
case (quantity@Some(_), _) => quantity
}
println(parse("kWh" , 100))
println(parse("J/m³", 100))
println(parse("GW" , 100))
println(parse("Au" , 100))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment