# Why is there no isless(::Int64, ::UnitRange{Int64})?

**URL:** <https://discourse.julialang.org/t/why-is-there-no-isless-int64-unitrange-int64/112648>\
**Category:** General Usage\
**Tags:** range, unitrange\
**Created:** [April 7, 2024, 4:09pm UTC](https://discourse.julialang.org/t/why-is-there-no-isless-int64-unitrange-int64/112648 "2024-04-07T16:09:57Z")\
**Posts on this page:** 6\
**Page:** 3

<div class="post-metadata">

**Author:** ![mnemnion](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mnemnion/32/206596_2.png) [@mnemnion](https://discourse.julialang.org/u/mnemnion)\
**Post date:** [April 10, 2024, 2:00pm UTC](https://discourse.julialang.org/t/why-is-there-no-isless-int64-unitrange-int64/112648/41 "2024-04-10T14:00:45Z")

</div>

> [@o314](#):
>
> One should better consider things like

Consider how? If you treat a `UnitRange` like a collection, it will behave like a collection. That’s true throughout Julia, consider `minimum(3, 4)` and `minimum(3, [4])`.

---

<div class="post-metadata">

**Author:** ![o314](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/o314/32/252_2.png) [@o314](https://discourse.julialang.org/u/o314)\
**Post date:** [April 10, 2024, 2:06pm UTC](https://discourse.julialang.org/t/why-is-there-no-isless-int64-unitrange-int64/112648/42 "2024-04-10T14:06:59Z")

</div>

Yes but it is o(n) instead of o(1) according to length(range)

---

<div class="post-metadata">

**Author:** ![o314](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/o314/32/252_2.png) [@o314](https://discourse.julialang.org/u/o314)\
**Post date:** [April 10, 2024, 2:12pm UTC](https://discourse.julialang.org/t/why-is-there-no-isless-int64-unitrange-int64/112648/43 "2024-04-10T14:12:39Z")

</div>

> [@screw\_dog](#):
>
> I think it’s generally better to not have default comparisons between scalars and collections

deserve a lot of likes . may be (certainly) more than what minimum and maximum merits nowaday

julia lacks a good statically dispatchable interface on iterable  
one should think about data shaping and mapping and not collapse them inadvertently. these should be treat like data invariants and preserve like beloved physical constant

---

<div class="post-metadata">

**Author:** ![mnemnion](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mnemnion/32/206596_2.png) [@mnemnion](https://discourse.julialang.org/u/mnemnion)\
**Post date:** [April 10, 2024, 3:22pm UTC](https://discourse.julialang.org/t/why-is-there-no-isless-int64-unitrange-int64/112648/44 "2024-04-10T15:22:48Z")

</div>

> [@o314](#):
>
> Yes but it is o(n) instead of o(1) according to length(range)

But `maximum` and `minimum` are optimized:

```julia
minimum(r::AbstractUnitRange) = isempty(r) ? throw(ArgumentError("range must be non-empty")) : first(r)
maximum(r::AbstractUnitRange) = isempty(r) ? throw(ArgumentError("range must be non-empty")) : last(r)

```

I would say that `scalar < minimum(vector)` is better code than `all(<(scalar), vector)`, many Vectors take advantage of the opportunity to give O(log(n)) or O(1) results for `minimum` and `maximum`.

---

<div class="post-metadata">

**Author:** ![FeatherPurple](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/featherpurple/32/209869_2.png) [@FeatherPurple](https://discourse.julialang.org/u/FeatherPurple)\
**Post date:** [March 20, 2025, 9:08am UTC](https://discourse.julialang.org/t/why-is-there-no-isless-int64-unitrange-int64/112648/45 "2025-03-20T09:08:47Z")

</div>

Currently, `<` is defined on `AbstractVector`s by lexicographic ordering. As such, you can already compare `UnitRange`s with each other. Your proposed ordering breaks transitivity, e.g. `(1:5) < (2:3) && (2:3) < 4` but `!((1:5) < 4)`.

---

<div class="post-metadata">

**Author:** ![o314](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/o314/32/252_2.png) [@o314](https://discourse.julialang.org/u/o314)\
**Post date:** [April 9, 2025, 1:54am UTC](https://discourse.julialang.org/t/why-is-there-no-isless-int64-unitrange-int64/112648/46 "2025-04-09T01:54:22Z")

</div>

If both order variant and type lifting are implicit, that will be a mess like your describe

[Previous page](https://discourse.julialang.org/t/why-is-there-no-isless-int64-unitrange-int64/112648.md?page=2)
