-
Notifications
You must be signed in to change notification settings - Fork 28
Add length #23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add length #23
Conversation
See discussion at #21, this should fix the issue.
Travis seems to have stopped for some bogus error, and I don't seem to have the privileges to restart it. |
end | ||
|
||
@test width(ClosedInterval(3,7)) ≡ 4 | ||
@test width(ClosedInterval(4.0,8.0)) ≡ 4.0 | ||
|
||
@test promote(1..2, 1.0..2.0) === (1.0..2.0, 1.0..2.0) | ||
|
||
@test length(I) == 4 | ||
@test length(J) == 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe add @test_throws MethodError length(1.2..2.4)
just to indicate that the absence of such a method is deliberate?
Thanks! Very nice of you to tackle this. |
Given this morning's discussions, I realize there may be one potential problem here: julia> 1..3 == 1.0..3.0
true But if we think of |
One option would be to change the parametrization to |
What would be the type for a I was thinking along similar lines, except that I would have |
Dates are an interesting case. You definitely want to allow a continuous interval, but I agree we don't seem to have a way to express that now. With discrete numbers, is there any reason you can't use a |
Two reasons:
If |
If point 2 means that what you effectively want is a struct TimeStepRange{T} <: OrdinalRange{T,Dates.Nanosecond}
start::T
stop::T
end
Base.step(::TimeStepRange) = Dates.Nanosecond(1) And then you could write a I tend to think of AbstractRanges as Intervals with a step, so I'm beginning to have second thoughts about supporting a notion of "number of elements" within an interval. That said, from a mathematical standpoint there is nothing wrong about using a discrete set as the "world." I think when we designed this package we were implicitly assuming intervals on the Real line. I'm still mulling this over. |
I wrote Also, feel free to revert this PR, it may not belong in this library. |
Add
Base.length(::ClosedInterval)
, which returns the number of elements in an interval for types which can be mapped to integers (currently all integers andDate
s).