aboutsummaryrefslogtreecommitdiff
path: root/utils.moon
diff options
context:
space:
mode:
authorBruce Hill <bitbucket@bruce-hill.com>2017-09-11 13:05:25 -0700
committerBruce Hill <bitbucket@bruce-hill.com>2017-09-11 13:05:25 -0700
commit5fef795cda854647e1ab2048299e71565621116a (patch)
treeecfda44f1dec5d707e301baf1199d3a391c6d740 /utils.moon
parentd218dcbd4217a8881f9a3e500ba17cd24e6e77f8 (diff)
probably working after refactor?
Diffstat (limited to 'utils.moon')
-rw-r--r--utils.moon20
1 files changed, 20 insertions, 0 deletions
diff --git a/utils.moon b/utils.moon
index ee97903..33e1312 100644
--- a/utils.moon
+++ b/utils.moon
@@ -31,6 +31,26 @@ utils = {
split: (str, sep="%s")->
[chunk for chunk in str\gmatch("[^#{sep}]+")]
+
+ accumulate: (glue, co)->
+ if co == nil then glue, co = "", glue
+ bits = {}
+ for bit in coroutine.wrap(co)
+ table.insert(bits, bit)
+ return table.concat(bits, glue)
+
+ range: (start,stop,step)->
+ if stop == nil
+ start,stop,step = 1,start,1
+ elseif step == nil
+ step = 1
+ return setmetatable({:start,:stop,:step}, {
+ __ipairs: =>
+ iter = (i)=>
+ if i < (@stop-@start)/@step
+ return i+1, @start+i*@step
+ return iter, @, 0
+ })
keys: (t)-> [k for k in pairs(t)]
values: (t)-> [v for _,v in pairs(t)]