small runnableExamples changes (#16181)

This commit is contained in:
flywind 2020-11-30 17:18:47 +08:00 • committed by GitHub
commit 735c06d7f1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -12,35 +12,33 @@
## Basic usage ## Basic usage
## =========== ## ===========
## ##
## .. code-block::
## import algorithm runnableExamples:
## type People = tuple
## type People = tuple year: int
## year: int name: string
## name: string
## var a: seq[People]
## var a: seq[People]
## a.add((2000, "John"))
## a.add((2000, "John")) a.add((2005, "Marie"))
## a.add((2005, "Marie")) a.add((2010, "Jane"))
## a.add((2010, "Jane"))
## # Sorting with default system.cmp
## # Sorting with default system.cmp a.sort()
## a.sort() assert a == @[(year: 2000, name: "John"), (year: 2005, name: "Marie"),
## assert a == @[(year: 2000, name: "John"), (year: 2005, name: "Marie"), (year: 2010, name: "Jane")]
## (year: 2010, name: "Jane")]
## proc myCmp(x, y: People): int =
## proc myCmp(x, y: People): int = if x.name < y.name: -1
## if x.name < y.name: -1 elif x.name == y.name: 0
## elif x.name == y.name: 0 else: 1
## else: 1
## # Sorting with custom proc
## # Sorting with custom proc a.sort(myCmp)
## a.sort(myCmp) assert a == @[(year: 2010, name: "Jane"), (year: 2000, name: "John"),
## assert a == @[(year: 2010, name: "Jane"), (year: 2000, name: "John"), (year: 2005, name: "Marie")]
## (year: 2005, name: "Marie")]
##
##
## See also ## See also
## ======== ## ========
## * `sequtils module<sequtils.html>`_ for working with the built-in seq type ## * `sequtils module<sequtils.html>`_ for working with the built-in seq type