Skip to content

Commit

Permalink
Add test case
Browse files Browse the repository at this point in the history
  • Loading branch information
Clyybber committed Feb 2, 2020
1 parent 0b96aa7 commit 124ed52
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion tests/closure/tcapture.nim
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,24 @@ discard """
output: '''
to be, or not to be'''
joinable: false
(v: 1)
(v: 1)
"""

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]
echo r[0] & ", or " & r[1]

type O = object
v: int
var o = O(v: 1)
var execute: proc()
capture [o]:
execute = proc() =
echo o
execute()
o.v = -1
execute()

0 comments on commit 124ed52

Please sign in to comment.