From f6e8da4332eb974a0e2d55872667f21aece57bc8 Mon Sep 17 00:00:00 2001 From: Simon Hafner Date: Tue, 11 Feb 2014 14:16:12 -0600 Subject: [PATCH] Added `$` for seq --- lib/system.nim | 12 ++++++++++++ tests/system/toString.nim | 5 +++++ 2 files changed, 17 insertions(+) create mode 100644 tests/system/toString.nim diff --git a/lib/system.nim b/lib/system.nim index 2acb989c5f..e7308f5d3d 100644 --- a/lib/system.nim +++ b/lib/system.nim @@ -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 diff --git a/tests/system/toString.nim b/tests/system/toString.nim new file mode 100644 index 0000000000..2a8ce1c0cc --- /dev/null +++ b/tests/system/toString.nim @@ -0,0 +1,5 @@ +discard """ + output:'''@[23, 45]''' +""" + +echo($(@[23, 45]))