Added $ for seq
This commit is contained in:
parent
e8c87d070a
commit
f6e8da4332
2 changed files with 17 additions and 0 deletions
|
|
@ -1672,6 +1672,18 @@ proc `$`*[T: set](x: T): string =
|
|||
result.add($value)
|
||||
result.add("}")
|
||||
|
||||
proc `$`*[T: seq](x: T): string =
|
||||
## generic ``$`` operator for seqs that is lifted from the components
|
||||
## of `x`. Example:
|
||||
##
|
||||
## .. code-block:: nimrod
|
||||
## $(@[23, 45]) == "@[23, 45]"
|
||||
result = "@["
|
||||
for value in items(x):
|
||||
if result.len > 2: result.add(", ")
|
||||
result.add($value)
|
||||
result.add("]")
|
||||
|
||||
when false:
|
||||
proc `$`*[T](a: openArray[T]): string =
|
||||
## generic ``$`` operator for open arrays that is lifted from the elements
|
||||
|
|
|
|||
5
tests/system/toString.nim
Normal file
5
tests/system/toString.nim
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
discard """
|
||||
output:'''@[23, 45]'''
|
||||
"""
|
||||
|
||||
echo($(@[23, 45]))
|
||||
Loading…
Add table
Add a link
Reference in a new issue