A data structure is a collection of data elements grouped under one name. These data elements, also known as member fields or just fields, can have different types. Adama has two types of data structures: record and message.
A record starts with the same rules as document variables, but wraps those variables within an additional layer of syntax. For instance, we can define a Person record with the following code:
And this record can be leveraged within the document:
or within another record:
A message is similar to a record except without any privacy awareness or privacy concerns. All fields within a message are public, and the expectation is that messages come from users. The following defines real-world message.
The types that are allowed in records is limited to:
- maybe<t> for any type in this list (except maybe and maybe)
- table<r> where r is a record
The best mental model for a record is a row within a table. As a convention, every record has a hidden field called id with type
int which can be revealed by defining it (without changing its type).
Records also have:
- index definitions to make tables go faster
- bubbles for viewer-dependent computation/view and privacy policies
Most types that can be defined within code can be defined within a messages. The exceptions are channels and futures.
Messages can also be constructed anonymously on the fly.
It is worth noting that the type of messages undergo static type rectification, so the above is 100% statically typed. It also leverages a simplified form of type inference such that messages of a known type can me constructed.
Given a message or record, we can convert it into a message type via the
The useful of this conversion will become clear when channels and futures are outlined..