2011-11-15 03:49:12 +00:00
|
|
|
|
2012-10-03 18:30:23 +00:00
|
|
|
-- see lists.moon for list comprehension tests
|
|
|
|
|
2011-11-15 03:49:12 +00:00
|
|
|
items = {1,2,3,4,5,6}
|
|
|
|
out = {k,k*2 for k in items}
|
|
|
|
|
|
|
|
|
|
|
|
x = hello: "world", okay: 2323
|
|
|
|
|
|
|
|
copy = {k,v for k,v in pairs x when k != "okay"}
|
|
|
|
|
2012-10-03 18:30:23 +00:00
|
|
|
--
|
|
|
|
|
|
|
|
{ unpack(x) for x in yes }
|
|
|
|
{ unpack(x) for x in *yes }
|
|
|
|
|
|
|
|
{ xxxx for x in yes }
|
|
|
|
{ unpack [a*i for i, a in ipairs x] for x in *{{1,2}, {3,4}} }
|
|
|
|
|
2013-01-12 23:09:17 +00:00
|
|
|
|
|
|
|
--
|
|
|
|
|
|
|
|
n1 = [i for i=1,10]
|
|
|
|
n2 = [i for i=1,10 when i % 2 == 1]
|
|
|
|
|
|
|
|
aa = [{x,y} for x=1,10 for y=5,14]
|
|
|
|
bb = [y for thing in y for i=1,10]
|
|
|
|
cc = [y for i=1,10 for thing in y]
|
|
|
|
dd = [y for i=1,10 when cool for thing in y when x > 3 when c + 3]
|
|
|
|
|
|
|
|
{"hello", "world" for i=1,10}
|
|
|
|
|
2016-09-25 21:20:57 +00:00
|
|
|
--
|
|
|
|
|
|
|
|
j = [a for {a,b,c} in things]
|
|
|
|
k = [a for {a,b,c} in *things]
|
|
|
|
i = [hello for {:hello, :world} in *things]
|
|
|
|
|
|
|
|
hj = {a,c for {a,b,c} in things}
|
|
|
|
hk = {a,c for {a,b,c} in *things}
|
|
|
|
hi = {hello,world for {:hello, :world} in *things}
|
|
|
|
|
|
|
|
ok(a,b,c) for {a,b,c} in things
|
|
|
|
|
2016-09-26 00:34:59 +00:00
|
|
|
--
|
|
|
|
|
|
|
|
[item for item in *items[1 + 2,3+4]]
|
|
|
|
[item for item in *items[hello! * 4, 2 - thing[4]]]
|
|
|
|
|
|
|
|
|
2016-09-25 21:20:57 +00:00
|
|
|
|
2013-01-12 23:09:17 +00:00
|
|
|
nil
|