Language
Structs
Use structs to define domain-specific record types with named fields and strong typing.
Structs let you group related fields into one named type. They are the main way to model records and domain-specific data in Tea.
A simple struct
Define a struct by naming the type and listing its fields. Each field carries an explicit type, which makes stored data predictable and easy to inspect at call sites.
struct User {
name: String
age: Int
}Once the type exists, construct values with named fields and access those fields with dot syntax.
const user = User(name: "Ada", age: 36)
@println(user.name)
@println(user.age)Structs in a larger example
Structs become more useful as programs grow. This example shows them alongside typed errors and formatted output in a longer file.
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)
]Current model
The checked-in sources use struct, not classes. Construction is explicit, fields are named, and generic structs use square-bracket type parameters such as Box[T].