aboutsummaryrefslogtreecommitdiff
path: root/lessons/src/lesson032_records
diff options
context:
space:
mode:
Diffstat (limited to 'lessons/src/lesson032_records')
-rw-r--r--lessons/src/lesson032_records/code.gleam17
-rw-r--r--lessons/src/lesson032_records/text.html10
2 files changed, 27 insertions, 0 deletions
diff --git a/lessons/src/lesson032_records/code.gleam b/lessons/src/lesson032_records/code.gleam
new file mode 100644
index 0000000..bd6da3c
--- /dev/null
+++ b/lessons/src/lesson032_records/code.gleam
@@ -0,0 +1,17 @@
+import gleam/io
+
+pub type SchoolPerson {
+ Teacher(name: String, subject: String)
+ Student(String)
+}
+
+pub fn main() {
+ let teacher1 = Teacher("Mr Schofield", "Physics")
+ let teacher2 = Teacher(name: "Miss Percy", subject: "Physics")
+ let student1 = Student("Koushiar")
+ let student2 = Student("Naomi")
+ let student3 = Student("Shaheer")
+
+ let school = [teacher1, teacher2, student1, student2, student3]
+ io.debug(school)
+}
diff --git a/lessons/src/lesson032_records/text.html b/lessons/src/lesson032_records/text.html
new file mode 100644
index 0000000..f515ccd
--- /dev/null
+++ b/lessons/src/lesson032_records/text.html
@@ -0,0 +1,10 @@
+<p>Variants of a record can hold other data within them.</p>
+<p>
+ These fields can be given labels, and like function argument labels they can
+ be optionally used when calling the record constructor. Typically labels will
+ be used for variants that define them.
+</p>
+<p>
+ It is common to have a custom type with one variant that holds data, this is
+ the Gleam equivalent of a struct or object in other languages.
+</p>