# How IntervalSets and UnitRanges compare in functionality?

**URL:** <https://discourse.julialang.org/t/how-intervalsets-and-unitranges-compare-in-functionality/31932>\
**Category:** Internals & Design\
**Tags:** question\
**Created:** [December 6, 2019, 4:26pm UTC](https://discourse.julialang.org/t/how-intervalsets-and-unitranges-compare-in-functionality/31932 "2019-12-06T16:26:37Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![sairus7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sairus7/32/10816_2.png) [@sairus7](https://discourse.julialang.org/u/sairus7)\
**Post date:** [December 6, 2019, 4:26pm UTC](https://discourse.julialang.org/t/how-intervalsets-and-unitranges-compare-in-functionality/31932/1 "2019-12-06T16:26:37Z")

</div>

[IntervalSets.jl](https://github.com/JuliaMath/IntervalSets.jl) and [UnitRanges](https://github.com/JuliaLang/julia/blob/master/base/range.jl)

Both represent some intervals with `start` – `end`.

Both support operations on sets: `in`, `union`, `intersect`, and so on.

UnitRanges define indexing and iterator interface, which is not true sot IntervalSets, but it _can_ be used for indexing with proper `toindex` transformation (see for example [SampledSignals.jl](https://github.com/JuliaAudio/SampledSignals.jl/blob/master/test/SampleBuf.jl) indexed in seconds interval).

IntervalSets can have infinite elements. Ranges are always finite and have an optional `step` parameter, that defaults to one. But IntervalSets are also finite for some types, like `ClosedInterval{Float64}(1,3)`) – then it’s similar to `1:3` range.

So, looks like IntervalSets is an abstraction over UnitRanges for intervals of infinite number of elements?

---

<div class="post-metadata">

**Author:** ![cstjean](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cstjean/32/1444_2.png) [@cstjean](https://discourse.julialang.org/u/cstjean)\
**Post date:** [December 6, 2019, 8:41pm UTC](https://discourse.julialang.org/t/how-intervalsets-and-unitranges-compare-in-functionality/31932/2 "2019-12-06T20:41:41Z")

</div>

They don’t represent the same things.

```julia
julia> 2.5 in ClosedInterval{Float64}(1,3)
true

julia> 2.5 in 1:3
false

```

Intervals are not enumerable (… naturally)
