From 1fada12a5f6a7af7cc22f49f02a9c63cef6ea130 Mon Sep 17 00:00:00 2001 From: Araq Date: Thu, 15 Nov 2012 08:45:16 +0100 Subject: improvements for first class iterators --- tests/run/titer8.nim | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/run/titer8.nim b/tests/run/titer8.nim index ae82c7d3c..d77159353 100644 --- a/tests/run/titer8.nim +++ b/tests/run/titer8.nim @@ -1,6 +1,11 @@ discard """ output: '''tada -ta da''' +1 +2 +3 +ta da1 +2 +3''' """ # Test first class iterator: @@ -21,13 +26,26 @@ iterator tokenize2(s: string, seps: set[char] = Whitespace): tuple[ yield (substr(s, i, j-1), false) i = j +iterator count3(): int {.closure.} = + yield 1 + yield 2 + yield 3 + for word, isSep in tokenize2("ta da", whiteSpace): if not isSep: stdout.write(word) echo "" proc inProc() = + for c in count3(): + echo c + for word, isSep in tokenize2("ta da", whiteSpace): stdout.write(word) + for c in count3(): + echo c + + inProc() + -- cgit 1.4.1-2-gfad0