Adds do notation example to algorithm.sort.
This commit is contained in:
parent
6975e77d43
commit
7da3c5e71e
1 changed files with 9 additions and 0 deletions
|
|
@ -150,6 +150,15 @@ proc sort*[T](a: var openArray[T],
|
|||
## # overload:
|
||||
## sort(myStrArray, system.cmp)
|
||||
##
|
||||
## You can inline adhoc comparison procs with the `do notation
|
||||
## <manual.html#do-notation>`_. Example:
|
||||
##
|
||||
## .. code-block:: nimrod
|
||||
##
|
||||
## people.sort do (x, y: Person) -> int:
|
||||
## result = cmp(x.surname, y.surname)
|
||||
## if result == 0:
|
||||
## result = cmp(x.name, y.name)
|
||||
var n = a.len
|
||||
var b: seq[T]
|
||||
newSeq(b, n div 2)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue