Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ New library features
* `RegexMatch` objects can now be used to construct `NamedTuple`s and `Dict`s ([#50988])
* `Lockable` is now exported ([#54595])
* New `ltruncate`, `rtruncate` and `ctruncate` functions for truncating strings to text width, accounting for char widths ([#55351])
* `isless` (and thus `cmp`, sorting, etc.) is now supported for zero-dimensional `AbstractArray`s ([#55772])

Standard library changes
------------------------
Expand Down
9 changes: 9 additions & 0 deletions base/abstractarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3047,6 +3047,15 @@ function cmp(A::AbstractVector, B::AbstractVector)
return cmp(length(A), length(B))
end

"""
isless(A::AbstractArray{<:Any,0}, B::AbstractArray{<:Any,0})

Return `true` when the only element of `A` is less than the only element of `B`.
"""
function isless(A::AbstractArray{<:Any,0}, B::AbstractArray{<:Any,0})
isless(only(A), only(B))
end

"""
isless(A::AbstractVector, B::AbstractVector)

Expand Down
8 changes: 8 additions & 0 deletions test/arrayops.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1404,6 +1404,14 @@ end
end

@testset "lexicographic comparison" begin
@testset "zero-dimensional" begin
vals = (0, 0.0, 1, 1.0)
for l ∈ vals
for r ∈ vals
@test cmp(fill(l), fill(r)) == cmp(l, r)
end
end
end
@test cmp([1.0], [1]) == 0
@test cmp([1], [1.0]) == 0
@test cmp([1, 1], [1, 1]) == 0
Expand Down