List.moon
import insert,concat,remove from table
class List
new: (t) =>
@ls = t or {}
add: (item) =>
insert @ls,item
insert: (idx,item) =>
insert @ls,idx,item
remove: (idx) => remove @ls,idx
len: => #@ls
__tostring: => '['..(concat @ls,',')..']'
find: (item) =>
for i = 1,#@ls
if @ls[i] == item then return i
remove_value: (item) =>
idx = self\find item
self\remove idx if idx
remove_values: (items) =>
for item in *items do self\remove_value item
index_by: (indexes) =>
List [@ls[idx] for idx in *indexes]
copy: => List [v for v in *@ls]
extend: (list) =>
other = if list.__class == List then list.ls else list
for v in *other do self\add v
self
__concat: (l1,l2) -> l1\copy!\extend l2
iter: =>
i,t,n = 0,@ls,#@ls
->
i += 1
if i <= n then t[i]
return List