Runnable Examples

team_scoreboard

Structs, errors, lambdas, and loops in one file.

What it demonstrates

  • Bundles structs, errors, lambdas, loops, and catch blocks in one file.
  • Good reference for language features outside CLI tooling.

Run it

tea examples/full/team_scoreboard.tea
tea build examples/full/team_scoreboard.tea
./bin/team_scoreboard

team_scoreboard.tea

struct Team {
  name: String
  wins: Int
  losses: Int
}

error TeamError {
  NotFound(name: String)
}

const format_team = |team: Team| => `${team.name}: ${team.wins} wins / ${team.losses} losses`

const teams = [
  Team(name: "Ada", wins: 7, losses: 3),
  Team(name: "Grace", wins: 9, losses: 1),
  Team(name: "Linus", wins: 5, losses: 5)
]

@println("Team scoreboard")

var index = 0

while index < @len(teams)
  @println(format_team(teams[index]))
  index = index + 1
end

def find_team(name: String) -> Team ! TeamError.NotFound
  var idx = 0

  while idx < @len(teams)
    var candidate = teams[idx]

    if candidate.name == name
      return candidate
    end

    idx = idx + 1
  end

  throw TeamError.NotFound(name)
end