# How to take union of interval elements in Interval Vector?

**URL:** <https://discourse.julialang.org/t/how-to-take-union-of-interval-elements-in-interval-vector/98422>\
**Category:** General Usage\
**Tags:** question\
**Created:** [May 6, 2023, 9:55pm UTC](https://discourse.julialang.org/t/how-to-take-union-of-interval-elements-in-interval-vector/98422 "2023-05-06T21:55:04Z")\
**Posts on this page:** 1\
**Showing post:** 12

<div class="post-metadata">

**Author:** ![lbenet](https://avatars.discourse-cdn.com/v4/letter/l/35a633/32.png) [@lbenet](https://discourse.julialang.org/u/lbenet)\
**Post date:** [May 7, 2023, 5:38pm UTC](https://discourse.julialang.org/t/how-to-take-union-of-interval-elements-in-interval-vector/98422/12 "2023-05-07T17:38:21Z")

</div>

You could do something like within IntervalArithemtic:

```julia
julia> using IntervalArithmetic

julia> X = [Interval(0.0, 0.1), Interval(1,2), Interval(0.1, 0.2), Interval(9,10), Interval(2,3), Interval(0.2, 0.3), Interval(10,11), Interval(2,3), Interval(9,10)];

julia> XY = Set{Interval{Float64}}()
Set{Interval{Float64}}()

julia> for x in X
    any(x .⊆ XY) && continue
    for y in X
        (x == y || isempty(x ∩ y)) && continue
        x = hull(x, y)
    end
    push!(XY, x)
end

julia> XY
Set{Interval{Float64}} with 3 elements:
  [0, 0.3]
  [1, 3]
  [9, 11]

```

---

_[View the full topic](https://discourse.julialang.org/t/how-to-take-union-of-interval-elements-in-interval-vector/98422)._
