diff --git a/src/Intervals.jl b/src/Intervals.jl index c525e92d..9be69d6d 100644 --- a/src/Intervals.jl +++ b/src/Intervals.jl @@ -16,6 +16,10 @@ abstract type AbstractInterval{T} end Base.eltype(::AbstractInterval{T}) where {T} = T +if VERSION >= v"0.7" + Base.broadcastable(x::AbstractInterval) = Ref(x) +end + include("inclusivity.jl") include("endpoint.jl") include("interval.jl") diff --git a/test/anchoredinterval.jl b/test/anchoredinterval.jl index 4f6a035f..dfbb7826 100644 --- a/test/anchoredinterval.jl +++ b/test/anchoredinterval.jl @@ -590,4 +590,15 @@ using Intervals: canonicalize end end end + + @testset "broadcasting" begin + # Check that we can broadcast a vector of anchored intervals against a scalar + + a = map([DateTime(2016, 8, 11), DateTime(2016, 8, 12)]) do dt + AnchoredInterval{Hour(-1), DateTime}(dt, Inclusivity(false, true)) + end + + mask = a .== a[2] + @test mask == [false, true] + end end