introduce capture macro (#12712)
capture works for more cases than `closureScope`.
This commit is contained in:
parent
65fd95bf85
commit
56cf3403b4
3 changed files with 41 additions and 0 deletions
12
tests/closure/tcapture.nim
Normal file
12
tests/closure/tcapture.nim
Normal 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]
|
||||
Loading…
Add table
Add a link
Reference in a new issue