aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2025-03-08 16:34:57 +0000
committerMichael Williamson <mike@zwobble.org>2025-03-08 16:34:57 +0000
commit90efb7b60b3e90729632c5334693ed1ddb1f24df (patch)
tree48a01dafcc0e98dc9382c99b320463f55f287aed /examples
parentdbe19ddd1fbb769f6f778dc1e9909bef70ece48f (diff)
Support divergent list building
Diffstat (limited to 'examples')
-rw-r--r--examples/44-list-builder/shed-examples.json56
-rw-r--r--examples/44-list-builder/src/Lists.shed23
2 files changed, 28 insertions, 1 deletions
diff --git a/examples/44-list-builder/shed-examples.json5 b/examples/44-list-builder/shed-examples.json5
index e6cc5e44..e14ac1b1 100644
--- a/examples/44-list-builder/shed-examples.json5
+++ b/examples/44-list-builder/shed-examples.json5
@@ -19,7 +19,11 @@ hellohello world\n\
\n\
buildListThenPrefix()\n\
hello world\n\
-hello",
+hello\
+\n\
+buildDivergentLists()\n\
+hello world\n\
+hello universe\n",
},
],
}
diff --git a/examples/44-list-builder/src/Lists.shed b/examples/44-list-builder/src/Lists.shed
index c6d01df5..389371d1 100644
--- a/examples/44-list-builder/src/Lists.shed
+++ b/examples/44-list-builder/src/Lists.shed
@@ -6,6 +6,7 @@ pub fun main() ! Io -> Unit {
buildListThenExtend!();
extendThenBuildPrefixAndList!();
buildListThenPrefix!();
+ buildDivergentLists!();
}
fun buildList() ! Io -> Unit {
@@ -107,3 +108,25 @@ fun buildListThenPrefix() ! Io -> Unit {
print!("\n");
}
+
+fun buildDivergentLists() ! Io -> Unit {
+ print!("buildDivergentLists()\n");
+
+ var builder1 = Lists.listBuilder[String]();
+ assign builder1 = builder1.add("hello");
+ val builder2 = builder1.add(" world\n");
+ val builder3 = builder1.add(" universe\n");
+
+ val list1 = builder2.build();
+ val list2 = builder3.build();
+
+ list1.forEach!(fn (element) ! Io {
+ print!(element);
+ });
+
+ list2.forEach!(fn (element) ! Io {
+ print!(element);
+ });
+
+ print!("\n");
+}