diff options
author | flywind <43030857+xflywind@users.noreply.github.com> | 2020-11-30 17:18:47 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-30 10:18:47 +0100 |
commit | 735c06d7f12ee3e4733754f57a1710e9d0dba5d9 (patch) | |
tree | 0b35dc4715fea8f18ed93dea4864eeb69c7613f3 /lib/pure | |
parent | dd5405cbcf7b12a41bd14591fdb2c706c87bf42f (diff) | |
download | Nim-735c06d7f12ee3e4733754f57a1710e9d0dba5d9.tar.gz |
small runnableExamples changes (#16181)
Diffstat (limited to 'lib/pure')
-rw-r--r-- | lib/pure/algorithm.nim | 58 |
1 files changed, 28 insertions, 30 deletions
diff --git a/lib/pure/algorithm.nim b/lib/pure/algorithm.nim index 2430e7330..f2e4848df 100644 --- a/lib/pure/algorithm.nim +++ b/lib/pure/algorithm.nim @@ -11,36 +11,34 @@ ## ## Basic usage ## =========== -## -## .. code-block:: -## import algorithm -## -## type People = tuple -## year: int -## name: string -## -## var a: seq[People] -## -## a.add((2000, "John")) -## a.add((2005, "Marie")) -## a.add((2010, "Jane")) -## -## # Sorting with default system.cmp -## a.sort() -## assert a == @[(year: 2000, name: "John"), (year: 2005, name: "Marie"), -## (year: 2010, name: "Jane")] -## -## proc myCmp(x, y: People): int = -## if x.name < y.name: -1 -## elif x.name == y.name: 0 -## else: 1 -## -## # Sorting with custom proc -## a.sort(myCmp) -## assert a == @[(year: 2010, name: "Jane"), (year: 2000, name: "John"), -## (year: 2005, name: "Marie")] -## -## +## + +runnableExamples: + type People = tuple + year: int + name: string + + var a: seq[People] + + a.add((2000, "John")) + a.add((2005, "Marie")) + a.add((2010, "Jane")) + + # Sorting with default system.cmp + a.sort() + assert a == @[(year: 2000, name: "John"), (year: 2005, name: "Marie"), + (year: 2010, name: "Jane")] + + proc myCmp(x, y: People): int = + if x.name < y.name: -1 + elif x.name == y.name: 0 + else: 1 + + # Sorting with custom proc + a.sort(myCmp) + assert a == @[(year: 2010, name: "Jane"), (year: 2000, name: "John"), + (year: 2005, name: "Marie")] + ## See also ## ======== ## * `sequtils module<sequtils.html>`_ for working with the built-in seq type |