Created
August 31, 2024 12:57
-
-
Save philipschwarz/877eb9773f1de425df4a14457a7b708c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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