Skip to content

Instantly share code, notes, and snippets.

@def-
Created December 31, 2014 16:52
Show Gist options
  • Save def-/177290281185d8dd9358 to your computer and use it in GitHub Desktop.
Save def-/177290281185d8dd9358 to your computer and use it in GitHub Desktop.
Iterators with shallowCopy
type TaskFn = iterator (): float
iterator a1(): float {.closure.} =
var k = 10
while k > 0:
echo "a1 ", k
dec k
yield 1.0
iterator a2(): float {.closure.} =
var k = 15
while k > 0:
echo "a2 ", k
dec k
yield 2.0
var
x = a1
y = a2
z: TaskFn
discard x()
shallowCopy(z, x)
shallowCopy(z, y)
discard x()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment