From 56cf3403b48943fe1fbc26377669d7d69fde4878 Mon Sep 17 00:00:00 2001 From: Judd Date: Tue, 10 Dec 2019 20:16:37 +0800 Subject: introduce capture macro (#12712) capture works for more cases than `closureScope`. --- tests/closure/tcapture.nim | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 tests/closure/tcapture.nim (limited to 'tests/closure') 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 -- cgit 1.4.1-2-gfad0