Skip to content

Commit

Permalink
Added a broadcastable method on 0.7 and tests for scalar broadcasting.
Browse files Browse the repository at this point in the history
  • Loading branch information
rofinn committed Jan 4, 2019
1 parent 810b8f4 commit 94eeb73
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Intervals.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
12 changes: 12 additions & 0 deletions test/anchoredinterval.jl
Original file line number Diff line number Diff line change
Expand Up @@ -590,4 +590,16 @@ using Intervals: canonicalize
end
end
end

@testset "broadcasting" begin
# Check that we can broadcast a vector of anchored intervals against a scalar

a = [
HourEnding(DateTime(2016, 8, 11)),
HourEnding(DateTime(2016, 8, 12)),
]

mask = a .== a[2]
@test mask == [false, true]
end
end

0 comments on commit 94eeb73

Please sign in to comment.