diff options
| author | s-ol <s-ol@users.noreply.github.com> | 2020-05-14 15:18:40 +0000 |
|---|---|---|
| committer | s-ol <s+removethis@s-ol.nu> | 2025-03-02 14:24:49 +0000 |
| commit | 6255ff9d6fcc36c752f9a0229db4eaecb5a9e466 (patch) | |
| tree | 1cebf8b34b98970910b18fc164f32e208ec68f0a /alv/util.moon | |
| parent | fix osc/sync (diff) | |
| download | alive-6255ff9d6fcc36c752f9a0229db4eaecb5a9e466.tar.gz alive-6255ff9d6fcc36c752f9a0229db4eaecb5a9e466.zip | |
pureops with arbitrary pattern
Diffstat (limited to 'alv/util.moon')
| -rw-r--r-- | alv/util.moon | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/alv/util.moon b/alv/util.moon index 316233b..e175600 100644 --- a/alv/util.moon +++ b/alv/util.moon @@ -31,7 +31,35 @@ ancestor = (klass) -> klass = klass.__parent klass +--- check whether a table is a 'plain' table +is_plain_table = (val) -> (type val) == 'table' and not val.__class + +--- recursively copy a value +deep_copy = (val) -> + if is_plain_table val + {(deep_copy k), (deep_copy v) for k,v in pairs val} + else + val + +--- map leaf values in a table +deep_map = (val, fn) -> + if is_plain_table val + {k, (deep_map v, fn) for k,v in pairs val} + else + fn val + +--- yield all leaf values in a table +deep_iter = (table) -> + for k, v in pairs table + if is_plain_table v + deep_iter v + else + coroutine.yield v + { :opairs :ancestor + :deep_copy + :deep_map + :deep_iter } |
