aboutsummaryrefslogtreecommitdiff
path: root/examples/44-list-builder/src
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/44-list-builder/src
parent6270bd1fd1edd376e87b2a45c0fd39879303e636 (diff)
Partial implementation of array and lists
Diffstat (limited to 'examples/44-list-builder/src')
-rw-r--r--examples/44-list-builder/src/Lists.shed43
1 files changed, 43 insertions, 0 deletions
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");
+}