Skip to content

Commit a660798

Browse files
Improve documentation of sort-related functions (#48387)
* document the `order` keyword in `sort!` * list explicitly the required properties of `lt` in `sort!` * clarify the sequence of "by" transformations if both `by` and `order` are given * show default values in the signatures for `searchsorted` and related functions * note that `by` is also applied to searched value in `searchsorted` and related * add `isunordered` to the manual (it's already exported) --------- Co-authored-by: Lilith Orion Hafner <lilithhafner@gmail.com>
1 parent b99f251 commit a660798

File tree

6 files changed

+161
-73
lines changed

6 files changed

+161
-73
lines changed

base/operators.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ isequal(x::AbstractFloat, y::Real ) = (isnan(x) & isnan(y)) | signequal(
143143
isless(x, y)
144144
145145
Test whether `x` is less than `y`, according to a fixed total order (defined together with
146-
[`isequal`](@ref)). `isless` is not defined on all pairs of values `(x, y)`. However, if it
146+
[`isequal`](@ref)). `isless` is not defined for pairs `(x, y)` of all types. However, if it
147147
is defined, it is expected to satisfy the following:
148148
- If `isless(x, y)` is defined, then so is `isless(y, x)` and `isequal(x, y)`,
149149
and exactly one of those three yields `true`.
@@ -154,13 +154,13 @@ Values that are normally unordered, such as `NaN`,
154154
are ordered after regular values.
155155
[`missing`](@ref) values are ordered last.
156156
157-
This is the default comparison used by [`sort`](@ref).
157+
This is the default comparison used by [`sort!`](@ref).
158158
159159
# Implementation
160160
Non-numeric types with a total order should implement this function.
161161
Numeric types only need to implement it if they have special values such as `NaN`.
162162
Types with a partial order should implement [`<`](@ref).
163-
See the documentation on [Alternate orderings](@ref) for how to define alternate
163+
See the documentation on [Alternate Orderings](@ref) for how to define alternate
164164
ordering methods that can be used in sorting and related functions.
165165
166166
# Examples
@@ -335,6 +335,8 @@ New types with a canonical partial order should implement this function for
335335
two arguments of the new type.
336336
Types with a canonical total order should implement [`isless`](@ref) instead.
337337
338+
See also [`isunordered`](@ref).
339+
338340
# Examples
339341
```jldoctest
340342
julia> 'a' < 'b'
@@ -1352,7 +1354,7 @@ corresponding position in `collection`. To get a vector indicating whether each
13521354
in `items` is in `collection`, wrap `collection` in a tuple or a `Ref` like this:
13531355
`in.(items, Ref(collection))` or `items .∈ Ref(collection)`.
13541356
1355-
See also: [`∉`](@ref).
1357+
See also: [`∉`](@ref), [`insorted`](@ref), [`contains`](@ref), [`occursin`](@ref), [`issubset`](@ref).
13561358
13571359
# Examples
13581360
```jldoctest
@@ -1390,8 +1392,6 @@ julia> [1, 2] .∈ ([2, 3],)
13901392
0
13911393
1
13921394
```
1393-
1394-
See also: [`insorted`](@ref), [`contains`](@ref), [`occursin`](@ref), [`issubset`](@ref).
13951395
"""
13961396
in
13971397

base/ordering.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ By(by) = By(by, Forward)
8787
"""
8888
Lt(lt)
8989
90-
`Ordering` which calls `lt(a, b)` to compare elements. `lt` should
91-
obey the same rules as implementations of [`isless`](@ref).
90+
`Ordering` that calls `lt(a, b)` to compare elements. `lt` must
91+
obey the same rules as the `lt` parameter of [`sort!`](@ref).
9292
"""
9393
struct Lt{T} <: Ordering
9494
lt::T
@@ -146,8 +146,8 @@ Construct an [`Ordering`](@ref) object from the same arguments used by
146146
Elements are first transformed by the function `by` (which may be
147147
[`identity`](@ref)) and are then compared according to either the function `lt`
148148
or an existing ordering `order`. `lt` should be [`isless`](@ref) or a function
149-
which obeys similar rules. Finally, the resulting order is reversed if
150-
`rev=true`.
149+
that obeys the same rules as the `lt` parameter of [`sort!`](@ref). Finally,
150+
the resulting order is reversed if `rev=true`.
151151
152152
Passing an `lt` other than `isless` along with an `order` other than
153153
[`Base.Order.Forward`](@ref) or [`Base.Order.Reverse`](@ref) is not permitted,

0 commit comments

Comments
 (0)