Skip to content
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

Default to short printing for REPL #168

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 20 additions & 14 deletions docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,23 +32,23 @@ This package defines:

```jldoctest
julia> a = 1..10
Interval{Int64, Closed, Closed}(1, 10)
[1 .. 10]

julia> b = 5..15
Interval{Int64, Closed, Closed}(5, 15)
[5 .. 15]

julia> intersect(a, b)
Interval{Int64, Closed, Closed}(5, 10)
[5 .. 10]
```

### Bounds

```jldoctest
julia> a = Interval{Closed, Closed}(1, 10)
Interval{Int64, Closed, Closed}(1, 10)
[1 .. 10]

julia> b = Interval{Open, Open}(5, 15)
Interval{Int64, Open, Open}(5, 15)
(5 .. 15)

julia> 5 in a
true
Expand All @@ -57,10 +57,10 @@ julia> 5 in b
false

julia> intersect(a, b)
Interval{Int64, Open, Closed}(5, 10)
(5 .. 10]

julia> c = Interval(15, 20)
Interval{Int64, Closed, Closed}(15, 20)
[15 .. 20]

julia> isempty(intersect(b, c))
true
Expand All @@ -70,15 +70,21 @@ true

```jldoctest
julia> a = Interval('a', 'z')
Interval{Char, Closed, Closed}('a', 'z')
[a .. z]

julia> repr(a)
"Interval{Char, Closed, Closed}('a', 'z')"

julia> string(a)
"[a .. z]"

julia> using Dates

julia> b = Interval{Closed, Open}(Date(2013), Date(2016))
Interval{Date, Closed, Open}(Date("2013-01-01"), Date("2016-01-01"))
[2013-01-01 .. 2016-01-01)

julia> repr(b)
"Interval{Date, Closed, Open}(Date(\"2013-01-01\"), Date(\"2016-01-01\"))"

julia> string(b)
"[2013-01-01 .. 2016-01-01)"
Expand Down Expand Up @@ -169,10 +175,10 @@ endpoints (taking bounds into account):

```jldoctest
julia> a = Interval{Closed, Open}(DateTime(2013, 2, 13), DateTime(2013, 2, 13, 1))
Interval{DateTime, Closed, Open}(DateTime("2013-02-13T00:00:00"), DateTime("2013-02-13T01:00:00"))
[2013-02-13T00:00:00 .. 2013-02-13T01:00:00)

julia> b = Interval{Open, Closed}(DateTime(2013, 2, 13), DateTime(2013, 2, 13, 1))
Interval{DateTime, Open, Closed}(DateTime("2013-02-13T00:00:00"), DateTime("2013-02-13T01:00:00"))
(2013-02-13T00:00:00 .. 2013-02-13T01:00:00]

julia> c = HourEnding(DateTime(2013, 2, 13, 1))
HourEnding{DateTime, Open, Closed}(DateTime("2013-02-13T01:00:00"))
Expand Down Expand Up @@ -219,13 +225,13 @@ endpoint should be used for rounding. Valid options are `:left`, `:right`, or

```jldoctest
julia> floor(Interval(0.0, 1.0), on=:left)
Interval{Float64, Closed, Closed}(0.0, 1.0)
[0.0 .. 1.0]

julia> floor(Interval(0.5, 1.0), on=:left)
Interval{Float64, Closed, Closed}(0.0, 0.5)
[0.0 .. 0.5]

julia> floor(Interval(0.5, 1.5), on=:right)
Interval{Float64, Closed, Closed}(0.0, 1.0)
[0.0 .. 1.0]
```

Anchored intervals default to rounding using the anchor point.
Expand Down
1 change: 1 addition & 0 deletions src/interval.jl
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ function Base.show(io::IO, interval::Interval{T,L,R}) where {T,L,R}
print(io, ")")
end
end
Base.show(io::IO, ::MIME"text/plain", interval::Interval) = print(io, interval)

function Base.print(io::IO, interval::AbstractInterval{T,L,R}) where {T,L,R}
# Print to io in order to keep properties like :limit and :compact
Expand Down