Skip to content

Do we need to provide ordered? #185

Open
@hyrodium

Description

@hyrodium

Base.minmax is almost the same, and IntervalSets.ordered is not used in IntervalSets.jl itself.

julia> using IntervalSets

julia> ordered(1,2)
(1, 2)

julia> minmax(1,2)
(1, 2)

julia> ordered(1.0,2)
(1.0, 2.0)

julia> minmax(1.0,2)
(1.0, 2.0)

julia> ordered("bc","ade")
("ade", "bc")

julia> minmax("bc","ade")
("ade", "bc")

The only differences are type promotion and if-statement.

julia> ordered([2.0], [1,3])
([1.0, 3.0], [2.0])

julia> minmax([2.0], [1,3])  # does not promote
([1, 3], [2.0])

IntervalSets.ordered uses ifelse.

https://github.com/JuliaMath/IntervalSets.jl/blob/master/src/IntervalSets.jl#L68

But Base.minmax uses ternary operator _?_:_

https://github.com/JuliaLang/julia/blob/8922eaa5517536eb51eb542f4543a8c6b82fda34/base/operators.jl#L514

I'm not sure which implementation is ideal, but Base.minmax should be fixed if IntervalSets.ordered wins in some aspect, and I think we don't have to provide our ordered function.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions