turbo-editors/turbo-moonbitpublic Fork 0
cc1f59535e31ad5d5a940f517c7375fbc8c663a0
Commits
Clone
git clone https://git.rickub.com/turbo-editors/turbo-moonbit.git
git clone ssh://git@rickub.com/turbo-editors/turbo-moonbit.git

Host key fingerprint (ed25519): SHA256:iycHnxEyq0Q7uyVpB7JlznP0G7JrTPXLYRcAU5CSLhc — verify it before your first connect.

📦 Turbo MoonBit cc1f595 · on cc1f59535e31ad5d5a940f517c7375fbc8c663a0 · k33g · yesterday
main.mbt · 37 lines · 1.1 KBMoonBit Blame HistoryRaw
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
///|
/// 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("")
}