From 8baadfc47832bbc3820e7d55adbbe5ddfaffedf3 Mon Sep 17 00:00:00 2001 From: s-ol Date: Wed, 2 Feb 2022 17:37:58 +0100 Subject: =?UTF-8?q?lib:=20rename=20math=20=E2=86=92=20math-simple,=20add?= =?UTF-8?q?=20vectorized=20math?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- alv/type.moon | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'alv') 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}]" -- cgit v1.2.3