Skip to content

Commit 245ab42

Browse files
authored
Easier to disambiguate in (#126)
* Easier to disambiguate in * version bump to v0.7.4 * define in for AbstractInterval * define in(v, ::Domain) * Define in(v, ::TypedEndpointsInterval)
1 parent 0661291 commit 245ab42

File tree

3 files changed

+18
-16
lines changed

3 files changed

+18
-16
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "IntervalSets"
22
uuid = "8197267c-284f-5f27-9208-e0e47529a953"
3-
version = "0.7.3"
3+
version = "0.7.4"
44

55
[deps]
66
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"

src/IntervalSets.jl

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -117,21 +117,22 @@ closedendpoints(d::TypedEndpointsInterval{:closed,:open}) = (true,false)
117117
closedendpoints(d::TypedEndpointsInterval{:open,:closed}) = (false,true)
118118
closedendpoints(d::TypedEndpointsInterval{:open,:open}) = (false,false)
119119

120-
121-
in(v, I::TypedEndpointsInterval{:closed,:closed}) = leftendpoint(I) v rightendpoint(I)
122-
in(v, I::TypedEndpointsInterval{:open,:open}) = leftendpoint(I) < v < rightendpoint(I)
123-
in(v, I::TypedEndpointsInterval{:closed,:open}) = leftendpoint(I) v < rightendpoint(I)
124-
in(v, I::TypedEndpointsInterval{:open,:closed}) = leftendpoint(I) < v rightendpoint(I)
125-
126-
in(v::Complex, I::TypedEndpointsInterval{:closed,:closed}) = isreal(v) && in(real(v), I)
127-
in(v::Complex, I::TypedEndpointsInterval{:open,:open}) = isreal(v) && in(real(v), I)
128-
in(v::Complex, I::TypedEndpointsInterval{:closed,:open}) = isreal(v) && in(real(v), I)
129-
in(v::Complex, I::TypedEndpointsInterval{:open,:closed}) = isreal(v) && in(real(v), I)
130-
131-
in(::Missing, I::TypedEndpointsInterval{:closed,:closed}) = !isempty(I) && missing
132-
in(::Missing, I::TypedEndpointsInterval{:open,:open}) = !isempty(I) && missing
133-
in(::Missing, I::TypedEndpointsInterval{:closed,:open}) = !isempty(I) && missing
134-
in(::Missing, I::TypedEndpointsInterval{:open,:closed}) = !isempty(I) && missing
120+
# We dispatch to _in to avoid ambiguities if packages define in(v::CustomType, I::TypedEndpointsInterval)
121+
in(v, I::TypedEndpointsInterval) = _in(v, I)
122+
_in(v, I::TypedEndpointsInterval{:closed,:closed}) = leftendpoint(I) v rightendpoint(I)
123+
_in(v, I::TypedEndpointsInterval{:open,:open}) = leftendpoint(I) < v < rightendpoint(I)
124+
_in(v, I::TypedEndpointsInterval{:closed,:open}) = leftendpoint(I) v < rightendpoint(I)
125+
_in(v, I::TypedEndpointsInterval{:open,:closed}) = leftendpoint(I) < v rightendpoint(I)
126+
127+
_in(v::Complex, I::TypedEndpointsInterval{:closed,:closed}) = isreal(v) && in(real(v), I)
128+
_in(v::Complex, I::TypedEndpointsInterval{:open,:open}) = isreal(v) && in(real(v), I)
129+
_in(v::Complex, I::TypedEndpointsInterval{:closed,:open}) = isreal(v) && in(real(v), I)
130+
_in(v::Complex, I::TypedEndpointsInterval{:open,:closed}) = isreal(v) && in(real(v), I)
131+
132+
_in(::Missing, I::TypedEndpointsInterval{:closed,:closed}) = !isempty(I) && missing
133+
_in(::Missing, I::TypedEndpointsInterval{:open,:open}) = !isempty(I) && missing
134+
_in(::Missing, I::TypedEndpointsInterval{:closed,:open}) = !isempty(I) && missing
135+
_in(::Missing, I::TypedEndpointsInterval{:open,:closed}) = !isempty(I) && missing
135136

136137
isempty(A::TypedEndpointsInterval{:closed,:closed}) = leftendpoint(A) > rightendpoint(A)
137138
isempty(A::TypedEndpointsInterval) = leftendpoint(A) rightendpoint(A)

test/runtests.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -827,6 +827,7 @@ struct IncompleteInterval <: AbstractInterval{Int} end
827827
@test eltype(I) === Int
828828
@test_throws ErrorException endpoints(I)
829829
@test_throws ErrorException closedendpoints(I)
830+
@test_throws MethodError 2 in I
830831
end
831832

832833
@testset "float" begin

0 commit comments

Comments
 (0)