Skip to content

Instantly share code, notes, and snippets.

@nmcb
Last active October 15, 2020 15:24
Show Gist options
  • Select an option

  • Save nmcb/af783ac0535537b284d5a56b5f3b2bb3 to your computer and use it in GitHub Desktop.

Select an option

Save nmcb/af783ac0535537b284d5a56b5f3b2bb3 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))
}
@bartbuijse
Copy link

Ah cool dat is natuurlijk ook een optie! (pun intended).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment