aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2025-03-08 15:22:47 +0000
committerMichael Williamson <mike@zwobble.org>2025-03-08 15:22:59 +0000
commite1d05f02ab7c865d752d38d0611b95583876bd8b (patch)
treeb4e7d91ac89df17a203e8186b96dfbe3ef6eb22f /examples
parent6270bd1fd1edd376e87b2a45c0fd39879303e636 (diff)
Partial implementation of array and lists
Diffstat (limited to 'examples')
-rw-r--r--examples/44-list-builder/shed-examples.json59
-rw-r--r--examples/44-list-builder/shed.json511
-rw-r--r--examples/44-list-builder/src/Lists.shed43
3 files changed, 63 insertions, 0 deletions
diff --git a/examples/44-list-builder/shed-examples.json5 b/examples/44-list-builder/shed-examples.json5
new file mode 100644
index 00000000..b669a2e6
--- /dev/null
+++ b/examples/44-list-builder/shed-examples.json5
@@ -0,0 +1,9 @@
+{
+ examples: [
+ {
+ project: ".",
+ bin: "lists",
+ expectedOutput: "buildList()\nhello world\n\nbuildSameListTwice()\nhello world\nhello world\n",
+ },
+ ],
+}
diff --git a/examples/44-list-builder/shed.json5 b/examples/44-list-builder/shed.json5
new file mode 100644
index 00000000..aaa788d6
--- /dev/null
+++ b/examples/44-list-builder/shed.json5
@@ -0,0 +1,11 @@
+{
+ bins: [
+ {
+ name: "lists",
+ mainNamespace: "Lists",
+ },
+ ],
+ dependencies: [
+ {path: "../../projects/std"},
+ ],
+}
diff --git a/examples/44-list-builder/src/Lists.shed b/examples/44-list-builder/src/Lists.shed
new file mode 100644
index 00000000..7744e8d8
--- /dev/null
+++ b/examples/44-list-builder/src/Lists.shed
@@ -0,0 +1,43 @@
+import Std/Lists;
+
+pub fun main() ! Io -> Unit {
+ buildList!();
+ buildSameListTwice!();
+}
+
+fun buildList() ! Io -> Unit {
+ print!("buildList()\n");
+
+ val builder = Lists.listBuilder[String]();
+ builder.add("hello");
+ builder.add(" world\n");
+
+ val list = builder.build();
+
+ list.forEach!(fn (element) ! Io {
+ print!(element);
+ });
+
+ print!("\n");
+}
+
+fun buildSameListTwice() ! Io -> Unit {
+ print!("buildSameListTwice()\n");
+
+ val builder = Lists.listBuilder[String]();
+ builder.add("hello");
+ builder.add(" world\n");
+
+ val list1 = builder.build();
+ val list2 = builder.build();
+
+ list1.forEach!(fn (element) ! Io {
+ print!(element);
+ });
+
+ list2.forEach!(fn (element) ! Io {
+ print!(element);
+ });
+
+ print!("\n");
+}