For those interested, I just hacked together the following implementation 
of what I was after. I've extended in, filter, and replace to the new type:

#Type BasicInterval
#My own extremely simple interval type that denotes all elements between 
start and stop
immutable BasicInterval{T}
    start::T
    stop::T
    function BasicInterval{T}(start::T, stop::T)
        start > stop && error("Start must be less than or equal to stop")
        new(start, stop)
    end
end
BasicInterval{T}(start::T, stop::T) = BasicInterval{T}(start, stop)
Base.in{T}(x::T, r::BasicInterval{T}) = (r.start <= x <= r.stop) ? true : 
false
Base.in{T}(x::AbstractVector{T}, r::BasicInterval{T}) = Bool[ in(x[n], r) 
for n = 1:length(x) ]
function Base.filter!{T}(x::AbstractVector{T}, r::BasicInterval{T})
    for n = length(x):-1:1
        !in(x[n], r) && deleteat!(x, n)
    end
    return(x)
end
Base.filter{T}(x::AbstractVector{T}, r::BasicInterval{T}) = 
filter!(deepcopy(x), r)
function replace!{T}(x::AbstractVector{T}, r::BasicInterval{T}, xNew::T)
    for n = 1:length(x)
        !in(x[n], r) && (x[n] = xNew)
    end
    return(x)
end
Base.replace{T}(x::AbstractVector{T}, r::BasicInterval{T}, xNew::T) = 
replace!(deepcopy(x), r, xNew)



On Friday, 3 June 2016 12:44:26 UTC+10, [email protected] wrote:
>
> Hi all,
>
> Is there any way to build a range that corresponds to the mathematical set 
> (-Inf, Inf)? I had a look at the source code in range.jl (which is very 
> readable!) and it doesn't appear that any of the Range types is suitable to 
> this task, e.g. StepRange doesn't take Float64 inputs, UnitRange(-Inf, Inf) 
> returns the range (-Inf, NaN) since the constructor returns convert
> (T,start+floor(stop-start)) for the stop value (I'm presuming for good 
> reasons that I'm not smart enough to understand), and FloatRange needs 
> concepts like step, len, and divisor that aren't well defined in this 
> context.
>
> Cheers,
>
> Colin
>
>
>

Reply via email to