aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authors-ol <s-ol@users.noreply.github.com>2020-05-14 15:19:02 +0000
committers-ol <s+removethis@s-ol.nu>2025-03-02 14:24:49 +0000
commitdefd84e93fcb7f4e95d7368e708774bd947fedb9 (patch)
tree31bcdb4545dfcf353ecab1d194b5b4a07f11e47d
parentpureops with arbitrary pattern (diff)
downloadalive-defd84e93fcb7f4e95d7368e708774bd947fedb9.tar.gz
alive-defd84e93fcb7f4e95d7368e708774bd947fedb9.zip
add array and struct constructors
-rw-r--r--alv-lib/array.moon22
-rw-r--r--alv-lib/struct.moon25
2 files changed, 47 insertions, 0 deletions
diff --git a/alv-lib/array.moon b/alv-lib/array.moon
new file mode 100644
index 0000000..752b1ff
--- /dev/null
+++ b/alv-lib/array.moon
@@ -0,0 +1,22 @@
+import PureOp, Constant, T, Array, val, evt from require 'alv.base'
+
+any = val! / evt!
+
+array = Constant.meta
+ meta:
+ name: 'array'
+ summary: "Construct an array."
+ examples: { '(array a b c…)' }
+ description: "Produces an array of values."
+
+ value: class extends PureOp
+ pattern: any!*0
+ type: (args) => Array #args, args[1]\type!
+
+ tick: =>
+ args = @unwrap_all!
+ @out\set args
+
+{
+ :array
+}
diff --git a/alv-lib/struct.moon b/alv-lib/struct.moon
new file mode 100644
index 0000000..e30c38d
--- /dev/null
+++ b/alv-lib/struct.moon
@@ -0,0 +1,25 @@
+import PureOp, Constant, T, Struct, val, evt from require 'alv.base'
+
+key = val.str / val.sym
+val = val! / evt!
+pair = (key + val)\named 'key', 'val'
+
+struct = Constant.meta
+ meta:
+ name: 'struct'
+ summary: "Construct an struct."
+ examples: { '(struct key1 val1 [key2 val2…])' }
+ description: "Produces an struct of values."
+
+ value: class extends PureOp
+ pattern: pair*0
+ type: (pairs) =>
+ Struct {key.result!, val\type! for {:key, :val} in *pairs}
+
+ tick: =>
+ pairs = @unwrap_all!
+ @out\set {key, val for {:key, :val} in *pairs}
+
+{
+ :struct
+}