Skip to content

Commit

Permalink
call reverse(o::Base.Ordering) to reverse ordering specified by o (
Browse files Browse the repository at this point in the history
  • Loading branch information
emmt authored and LilithHafner committed Feb 22, 2022
1 parent d7c2d54 commit 0f5d52e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
10 changes: 9 additions & 1 deletion base/ordering.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module Order
import ..@__MODULE__, ..parentmodule
const Base = parentmodule(@__MODULE__)
import .Base:
AbstractVector, @propagate_inbounds, isless, identity, getindex,
AbstractVector, @propagate_inbounds, isless, identity, getindex, reverse,
+, -, !, &, <, |

## notions of element ordering ##
Expand Down Expand Up @@ -46,6 +46,14 @@ ReverseOrdering(rev::ReverseOrdering) = rev.fwd
ReverseOrdering(fwd::Fwd) where {Fwd} = ReverseOrdering{Fwd}(fwd)
ReverseOrdering() = ReverseOrdering(ForwardOrdering())

"""
reverse(o::Base.Ordering)
reverses ordering specified by `o`.
"""
reverse(o::Ordering) = ReverseOrdering(o)

const DirectOrdering = Union{ForwardOrdering,ReverseOrdering{ForwardOrdering}}

"""
Expand Down
2 changes: 2 additions & 0 deletions test/ordering.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,5 @@ struct SomeOtherOrder <: Base.Order.Ordering end

@test_throws ErrorException sort([1, 2, 3], lt=(a, b) -> a - b < 0, order=SomeOtherOrder())

@test reverse(Forward) === Reverse
@test reverse(Reverse) === Forward

0 comments on commit 0f5d52e

Please sign in to comment.