aboutsummaryrefslogtreecommitdiff
path: root/examples/learn/31-array-algorithms.zc
diff options
context:
space:
mode:
Diffstat (limited to 'examples/learn/31-array-algorithms.zc')
-rw-r--r--examples/learn/31-array-algorithms.zc11
1 files changed, 11 insertions, 0 deletions
diff --git a/examples/learn/31-array-algorithms.zc b/examples/learn/31-array-algorithms.zc
new file mode 100644
index 0000000..d74bc74
--- /dev/null
+++ b/examples/learn/31-array-algorithms.zc
@@ -0,0 +1,11 @@
+namespace;
+include rt, std;
+
+fn main() {
+ int[?] values = {1, 2, 3, 4, 5};
+ let doubled = values.map(fn(e) { return e * 2; });
+ let large = doubled.filter(fn(e) { return e > 4; });
+ rt.put_n(values.find(3)); rt.put_c(32);
+ rt.put_n(values.find_if(fn(e) { return e > 4; })); rt.put_c(32);
+ rt.put_n(large.reduce(0, fn(total, e) { return total + e; })); rt.put_c(10);
+}