summary refs log tree commit diff stats
path: root/tests/closure
diff options
context:
space:
mode:
authorJudd <foldl@outlook.com>2019-12-10 20:16:37 +0800
committerAndreas Rumpf <rumpf_a@web.de>2019-12-10 13:16:37 +0100
commit56cf3403b48943fe1fbc26377669d7d69fde4878 (patch)
tree1d95829b84112f4b2f365af51285a2e4dd60c796 /tests/closure
parent65fd95bf85d7ca05acec769fabbcdc153de3383d (diff)
downloadNim-56cf3403b48943fe1fbc26377669d7d69fde4878.tar.gz
introduce capture macro (#12712)
capture works for more cases than `closureScope`.
Diffstat (limited to 'tests/closure')
-rw-r--r--tests/closure/tcapture.nim12
1 files changed, 12 insertions, 0 deletions
diff --git a/tests/closure/tcapture.nim b/tests/closure/tcapture.nim
new file mode 100644
index 000000000..304a76285
--- /dev/null
+++ b/tests/closure/tcapture.nim
@@ -0,0 +1,12 @@
+discard """
+  output: '''
+to be, or not to be'''
+  joinable: false
+"""
+
+import sequtils, sugar
+
+let m = @[proc (s: string): string = "to " & s, proc (s: string): string = "not to " & s]
+var l = m.mapIt(capture([it], proc (s: string): string = it(s)))
+let r = l.mapIt(it("be"))
+echo r[0] & ", or " & r[1]
\ No newline at end of file
href='/ahoang/Nim/commit/tools/deinstall.tmpl?h=devel&id=66a7e3d37c0303997a6b1a3b7ec263dfb8c07748'>66a7e3d37 ^
39d802188 ^
66a7e3d37 ^






39d802188 ^
6c88debd5 ^






39d802188 ^
66a7e3d37 ^






6c88debd5 ^
66a7e3d37 ^



8087f51d1 ^
eaf4da041 ^
66a7e3d37 ^

6c88debd5 ^
eaf4da041 ^
66a7e3d37 ^





6c88debd5 ^





66a7e3d37 ^

765366c1f ^
66a7e3d37 ^




6c88debd5 ^
66a7e3d37 ^

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81