aboutsummaryrefslogtreecommitdiffstats
path: root/alv
diff options
context:
space:
mode:
Diffstat (limited to 'alv')
-rw-r--r--alv/type.moon13
1 files changed, 13 insertions, 0 deletions
diff --git a/alv/type.moon b/alv/type.moon
index 4f38e02..765cab2 100644
--- a/alv/type.moon
+++ b/alv/type.moon
@@ -119,6 +119,12 @@ class Struct extends Type
get: (key) =>
assert @types[key], Error 'index', "#{@} has no '#{key}' key"
+ --- iterate over contained keys and types
+ -- each iteration, returns a key and associated type
+ -- @treturn string key
+ -- @treturn Type associated type
+ iter_keys: => next, @types, nil
+
--- create a new struct type with a subset of keys.
project: (keys) =>
types = {}
@@ -161,6 +167,13 @@ class Array extends Type
assert key >= 0 and key < @size, Error 'index', "index '#{key}' out of range!"
@type
+ array_next = (i) => if i < @size then i + 1, @type
+ --- iterate over contained types
+ -- each iteration, returns a key and associated type
+ -- @treturn number key
+ -- @treturn Type associated type
+ iter_keys: => array_next, @, 0
+
__eq: (other) => other.__class == Array and @size == other.size and @type == other.type
__tostring: => "#{@type}[#{@size}]"