Skip to content

Commit b6faae6

Browse files
committed
Union{Integer,StaticInt}
1 parent 7eb8c65 commit b6faae6

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

Project.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "CloseOpenIntervals"
22
uuid = "fb6a15b2-703c-40df-9091-08a04967cfa9"
33
authors = ["chriselrod <[email protected]> and contributors"]
4-
version = "0.1.7"
4+
version = "0.1.8"
55

66
[deps]
77
ArrayInterface = "4fba245c-0d91-5ea0-9b3e-6abc04ee57a9"

src/CloseOpenIntervals.jl

+9-7
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,18 @@ module CloseOpenIntervals
33
using Static: StaticInt, Zero, One
44
export CloseOpen, SafeCloseOpen
55

6-
abstract type AbstractCloseOpen{L <: Union{Int,StaticInt}, U <: Union{Int,StaticInt}} <: AbstractUnitRange{Int} end
6+
const IntegerType = Union{Integer,StaticInt}
7+
8+
abstract type AbstractCloseOpen{L <: IntegerType, U <: IntegerType} <: AbstractUnitRange{Int} end
79
for T (:CloseOpen,:SafeCloseOpen)
810
@eval begin
9-
struct $T{L <: Union{Int,StaticInt}, U <: Union{Int,StaticInt}} <: AbstractCloseOpen{L,U}
11+
struct $T{L <: IntegerType, U <: IntegerType} <: AbstractCloseOpen{L,U}
1012
start::L
1113
upper::U
12-
@inline $T{L,U}(l::L,u::U) where {L <: Union{Int,StaticInt}, U <: Union{Int,StaticInt}} = new{L,U}(l,u)
14+
@inline $T{L,U}(l::L,u::U) where {L <: IntegerType, U <: IntegerType} = new{L,U}(l,u)
1315
end
1416
@inline $T(s::S, u::U) where {S,U} = $T{S,U}(s, u)
15-
@inline $T(len::T) where {T<:Union{Int,StaticInt}} = $T{Zero,T}(Zero(), len)
17+
@inline $T(len::T) where {T<:IntegerType} = $T{Zero,T}(Zero(), len)
1618
end
1719
end
1820

@@ -62,14 +64,14 @@ SafeCloseOpen
6264
@inline Base.first(r::AbstractCloseOpen) = getfield(r,:start)
6365
@inline Base.first(r::AbstractCloseOpen{StaticInt{F}}) where {F} = F
6466
@inline Base.step(::AbstractCloseOpen) = 1
65-
@inline Base.last(r::AbstractCloseOpen{<:Union{Int,StaticInt},I}) where {I} = getfield(r,:upper) - 1
66-
@inline Base.last(r::AbstractCloseOpen{<:Union{Int,StaticInt},StaticInt{L}}) where {L} = L - 1
67+
@inline Base.last(r::AbstractCloseOpen{<:IntegerType,I}) where {I} = getfield(r,:upper) - 1
68+
@inline Base.last(r::AbstractCloseOpen{<:IntegerType,StaticInt{L}}) where {L} = L - 1
6769
@inline Base.length(r::AbstractCloseOpen) = getfield(r,:upper) - getfield(r,:start)
6870
@inline Base.length(r::AbstractCloseOpen{Zero}) = getfield(r,:upper)
6971

7072
@inline Base.iterate(r::CloseOpen) = (i = Int(first(r)); (i, i))
7173
@inline Base.iterate(r::SafeCloseOpen) = (i = Int(first(r)); i getfield(r, :upper) ? nothing : (i, i))
72-
@inline Base.iterate(r::AbstractCloseOpen, i::Union{Int,StaticInt}) = (i += one(i)) getfield(r, :upper) ? nothing : (i, i)
74+
@inline Base.iterate(r::AbstractCloseOpen, i::IntegerType) = (i += one(i)) getfield(r, :upper) ? nothing : (i, i)
7375

7476
import ArrayInterface
7577
ArrayInterface.known_first(::Type{<:AbstractCloseOpen{StaticInt{F}}}) where {F} = F

0 commit comments

Comments
 (0)