diff options
author | Judd <foldl@outlook.com> | 2019-12-10 20:16:37 +0800 |
---|---|---|
committer | Andreas Rumpf <rumpf_a@web.de> | 2019-12-10 13:16:37 +0100 |
commit | 56cf3403b48943fe1fbc26377669d7d69fde4878 (patch) | |
tree | 1d95829b84112f4b2f365af51285a2e4dd60c796 /tests/closure | |
parent | 65fd95bf85d7ca05acec769fabbcdc153de3383d (diff) | |
download | Nim-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.nim | 12 |
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 |