Skip to content

Commit 27a6079

Browse files
authored
union and intersect for SOneTo (#1197)
* union and intersect for SOneTo * Test for exact match
1 parent 03c13a0 commit 27a6079

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

src/SOneTo.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,6 @@ Base.promote_rule(a::Type{Base.OneTo{T}}, ::Type{SOneTo{n}}) where {T,n} =
7878
function Base.reduced_indices(inds::Tuple{SOneTo,Vararg{SOneTo}}, d::Int)
7979
Base.reduced_indices(map(Base.OneTo, inds), d)
8080
end
81+
82+
Base.intersect(r::SOneTo{n1}, s::SOneTo{n2}) where {n1,n2} = SOneTo(min(n1, n2))
83+
Base.union(r::SOneTo{n1}, s::SOneTo{n2}) where {n1,n2} = SOneTo(max(n1, n2))

test/core.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,5 +205,8 @@
205205
@test convert(StaticArrays.SOneTo{2}, 1:2) === StaticArrays.SOneTo{2}()
206206
@test_throws DimensionMismatch StaticArrays.SOneTo{2}(1:3)
207207
@test_throws DimensionMismatch StaticArrays.SOneTo{2}(1:1)
208+
209+
@test @inferred(intersect(SOneTo(2), SOneTo(4))) === SOneTo(2)
210+
@test @inferred(union(SOneTo(2), SOneTo(4))) === SOneTo(4)
208211
end
209212
end

0 commit comments

Comments
 (0)