introduce capture macro (#12712)

capture works for more cases than `closureScope`.
This commit is contained in:
Judd 2019-12-10 20:16:37 +08:00 • committed by Andreas Rumpf
commit 56cf3403b4
3 changed files with 41 additions and 0 deletions

View file

@ -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]