I want to define defaults for a read-only AbstractVector{Bool}
argument to a function and so far used falses(n)
. However, this allocates a full BitArray
.
I guess should be a type similar to a Range
that can do this job, similar to:
struct Repeat{T,N} end
Base.getindex(r::Repeat{T,N},i::Int) where {T,N} =
(1 <= i <= N) ? T : throw(BoundsError(r,i))
Base.length(r::Repeat{T,N}) where {T,N} = N
Before I invest much time in developing such a type with the full Array interface, I ask how such cases are handled so far in Julia?
4 posts - 3 participants