aboutsummaryrefslogtreecommitdiff
path: root/spec/inputs/comprehension.yue
diff options
context:
space:
mode:
authorLi Jin <dragon-fly@qq.com>2021-02-17 11:22:07 +0800
committerLi Jin <dragon-fly@qq.com>2021-02-17 11:22:07 +0800
commit7066392d1c974065181d95d93274136dcd625d43 (patch)
treecf51eafc2c52cbc12246a306bca172d799193d30 /spec/inputs/comprehension.yue
parent90cd12ad9ef465f3e435e1bd034dcfbe4e19d016 (diff)
downloadyuescript-7066392d1c974065181d95d93274136dcd625d43.tar.gz
yuescript-7066392d1c974065181d95d93274136dcd625d43.tar.bz2
yuescript-7066392d1c974065181d95d93274136dcd625d43.zip
stop reusing variables, rename project.
Diffstat (limited to 'spec/inputs/comprehension.yue')
-rw-r--r--spec/inputs/comprehension.yue52
1 files changed, 52 insertions, 0 deletions
diff --git a/spec/inputs/comprehension.yue b/spec/inputs/comprehension.yue
new file mode 100644
index 0000000..b6adb94
--- /dev/null
+++ b/spec/inputs/comprehension.yue
@@ -0,0 +1,52 @@
1
2-- see lists.moon for list comprehension tests
3
4items = {1,2,3,4,5,6}
5out = {k,k*2 for k in items}
6
7
8x = hello: "world", okay: 2323
9
10copy = {k,v for k,v in pairs x when k != "okay"}
11
12--
13
14_ = { unpack(x) for x in yes }
15_ = { unpack(x) for x in *yes }
16
17_ = { xxxx for x in yes }
18_ = { unpack [a*i for i, a in ipairs x] for x in *{{1,2}, {3,4}} }
19
20
21--
22
23n1 = [i for i=1,10]
24n2 = [i for i=1,10 when i % 2 == 1]
25
26aa = [{x,y} for x=1,10 for y=5,14]
27bb = [y for thing in y for i=1,10]
28cc = [y for i=1,10 for thing in y]
29dd = [y for i=1,10 when cool for thing in y when x > 3 when c + 3]
30
31_ = {"hello", "world" for i=1,10}
32
33--
34
35j = [a for {a,b,c} in things]
36k = [a for {a,b,c} in *things]
37i = [hello for {:hello, :world} in *things]
38
39hj = {a,c for {a,b,c} in things}
40hk = {a,c for {a,b,c} in *things}
41hi = {hello,world for {:hello, :world} in *things}
42
43ok(a,b,c) for {a,b,c} in things
44
45--
46
47_ = [item for item in *items[1 + 2,3+4]]
48_ = [item for item in *items[hello! * 4, 2 - thing[4]]]
49
50list = [item?\invoke 123 for item in items]
51
52nil