Skip to content

Commit

Permalink
Start Bi-infinite ranges
Browse files Browse the repository at this point in the history
  • Loading branch information
dlfivefifty committed Dec 3, 2022
1 parent b17e35b commit fa799fb
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
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

0 comments on commit fa799fb

Please sign in to comment.