Skip to content
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
2 changes: 1 addition & 1 deletion src/InfiniteArrays.jl
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ end
return LazyArrays.searchsortedlast_recursive(n, x, args...)
end


include("biinfrange.jl")


end # module
21 changes: 21 additions & 0 deletions src/biinfrange.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
"""
BiInfUnitRange()

Represent -∞:∞ with offset indexing
"""
struct BiInfUnitRange{T<:Real} <: AbstractInfUnitRange{T} end

BiInfUnitRange() = BiInfUnitRange{Int}()

AbstractArray{T}(a::BiInfUnitRange) where T<:Real = BiInfUnitRange{T}(a)
AbstractVector{T}(a::BiInfUnitRange) where T<:Real = BiInfUnitRange{T}(a)

unitrange(a::BiInfUnitRange) = a
Base.has_offset_axes(::BiInfUnitRange) = true

getindex(v::BiInfUnitRange{T}, i::Integer) where T = convert(T, i)
axes(::BiInfUnitRange) = (BiInfUnitRange(),)
first(::BiInfUnitRange) = -∞
show(io::IO, ::BiInfUnitRange{Int}) = print(io, "BiInfUnitRange()")

getindex(r::BiInfUnitRange{T}, s::AbstractUnitRange{<:Integer}) where T = convert(AbstractVector{T}, s)
8 changes: 8 additions & 0 deletions test/test_biinfrange.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using InfiniteArrays, Base64, Test
using InfiniteArrays: BiInfUnitRange

@testset "-∞:∞" begin
r = BiInfUnitRange()
@test stringmime("text/plain", r) == "BiInfUnitRange()"

end