Skip to content

Instantly share code, notes, and snippets.

@philipschwarz
Created August 31, 2024 12:57
Show Gist options
  • Save philipschwarz/877eb9773f1de425df4a14457a7b708c to your computer and use it in GitHub Desktop.
Save philipschwarz/877eb9773f1de425df4a14457a7b708c to your computer and use it in GitHub Desktop.
import anticipation.Text
import gossamer.t
import quantitative.{Kilograms, Metres, Quantity}
import turbulence.Out
type Bmi = Quantity[Kilograms[1] & Metres[-2]]
case class Person(
name: Text,
age: Int,
height: Quantity[Metres[1]],
weight: Quantity[Kilograms[1]]):
def bmi: Bmi = weight / (height * height)
@main
def run(path: Text): Unit = Out.println:
mend:
case ParseError(line, _, _) => t"There was a parsing error at $line."
case PathError(_, reason) => t"There was a path error because $reason."
case IoError(_) => t"There was an I/O error."
.within:
val json = Json.parse(path.decode[Path].as[File])
val data = unsafely(json.as[List[Person]])
val mean = data.map(_.bmi) / data.length
t"The average BMI is $mean"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment