diff options
-rwxr-xr-x | doc/tut2.txt | 66 | ||||
-rw-r--r-- | lib/pure/collections/sequtils.nim | 6 | ||||
-rwxr-xr-x | tests/run/ttoseq.nim | 11 |
3 files changed, 44 insertions, 39 deletions
diff --git a/doc/tut2.txt b/doc/tut2.txt index 9c55b0e35..9f9dbe2db 100755 --- a/doc/tut2.txt +++ b/doc/tut2.txt @@ -439,39 +439,39 @@ Exception hierarchy If you want to create your own exceptions you can inherit from E_Base, but you can also inherit from one of the existing exceptions if they fit your purpose. -The exception tree is: - -* E_Base - * EAsynch - * EControlC - * ESynch - * ESystem - * EIO - * EOS - * EInvalidLibrary - * EResourceExhausted - * EOutOfMemory - * EStackOverflow - * EArithmetic - * EDivByZero - * EOverflow - * EAccessViolation - * EAssertionFailed - * EInvalidValue - * EInvalidKey - * EInvalidIndex - * EInvalidField - * EOutOfRange - * ENoExceptionToReraise - * EInvalidObjectAssignment - * EInvalidObjectConversion - * EFloatingPoint - * EFloatInvalidOp - * EFloatDivByZero - * EFloatOverflow - * EFloatUnderflow - * EFloatInexact - * EDeadThread +The exception tree is:: + + * E_Base + * EAsynch + * EControlC + * ESynch + * ESystem + * EIO + * EOS + * EInvalidLibrary + * EResourceExhausted + * EOutOfMemory + * EStackOverflow + * EArithmetic + * EDivByZero + * EOverflow + * EAccessViolation + * EAssertionFailed + * EInvalidValue + * EInvalidKey + * EInvalidIndex + * EInvalidField + * EOutOfRange + * ENoExceptionToReraise + * EInvalidObjectAssignment + * EInvalidObjectConversion + * EFloatingPoint + * EFloatInvalidOp + * EFloatDivByZero + * EFloatOverflow + * EFloatUnderflow + * EFloatInexact + * EDeadThread See the `system <system.html>`_ module for a description of each exception. diff --git a/lib/pure/collections/sequtils.nim b/lib/pure/collections/sequtils.nim index 82679bb7f..0fda5700e 100644 --- a/lib/pure/collections/sequtils.nim +++ b/lib/pure/collections/sequtils.nim @@ -63,3 +63,9 @@ template filterIt*(seq1, pred: expr): expr {.immediate, dirty.} = if pred: result.add(it) result +template toSeq*(iter: expr): expr {.immediate.} = + ## Transforms any iterator into a sequence. + var result {.gensym.}: seq[type(iter)] = @[] + for x in iter: add(result, x) + result + diff --git a/tests/run/ttoseq.nim b/tests/run/ttoseq.nim index ec49489d0..34cc4824b 100755 --- a/tests/run/ttoseq.nim +++ b/tests/run/ttoseq.nim @@ -1,12 +1,11 @@ discard """ - output: "23456" + output: "2345623456" """ -template toSeq*(iter: expr): expr {.immediate.} = - var result: seq[type(iter)] = @[] - for x in iter: add(result, x) - result - +import sequtils + +for x in toSeq(countup(2, 6)): + stdout.write(x) for x in items(toSeq(countup(2, 6))): stdout.write(x) |