///| /// Measures a handful of shapes and prints what it found. /// /// Run it from the project root with `moon run cmd/main`, or from the /// editor's MoonBit menu with **Run** and `cmd/main`. fn main { let circles = [ @shapes.Circle::{ radius: 1.0, }, @shapes.Circle::{ radius: 2.5, }, @shapes.Circle::{ radius: 0.5, }, ] let rects = [ @shapes.Rect::{ width: 3.0, height: 4.0, }, @shapes.Rect::{ width: 1.5, height: 1.5, }, ] report("circles", circles) report("rectangles", rects) report("nothing at all", ([] : Array[@shapes.Circle])) } ///| /// report prints the total and the largest of a list, and says so plainly when /// the list is empty rather than letting the error escape. fn[T : @shapes.Area + Show] report(what : String, shapes : Array[T]) -> Unit { println("── \{what} ──") try { let sum = @shapes.total(shapes) println(" total area: \{sum}") } catch { @shapes.NoShapes => println(" no shapes were given") } match @shapes.largest(shapes) { Some(shape) => println(" largest: \{shape}") None => println(" largest: none") } println("") }