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
4 changes: 3 additions & 1 deletion src/SentinelArrays.jl
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,9 @@ Base.@propagate_inbounds function Base.setindex!(A::SentinelArray{T, N, S, V}, v
end

# other AbstractArray functions
function Base.reverse(A::SentinelVector, s::Integer=first(LinearIndices(A)), n::Integer=last(LinearIndices(A)))
function Base.reverse(A::SentinelVector{T, S}, s::Integer=first(LinearIndices(A)), n::Integer=last(LinearIndices(A))) where {T, S}
# with an `undef` sentinel the parent has unassigned slots, and reversing the parent would read them
S === UndefInitializer && return reverse!(Base.unaliascopy(A), s, n)
return SentinelArray(reverse(parent(A), s, n), A.sentinel, A.value)
end

Expand Down
9 changes: 9 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@ x[1] = x.sentinel
r = reverse(x)
@test x.sentinel == r.sentinel

@testset "reverse a SentinelVector with unset slots" begin
s = SentinelVector{String}(undef, 3)
s[1] = "a"
s[3] = "c"
@test isequal(reverse(s), ["c", missing, "a"])
@test isequal(reverse(s, 2, 3), ["a", "c", missing])
@test isequal(s, ["a", missing, "c"])
end

@test size(x) == (10,)
x[1] = 3
@test x[1] === 3
Expand Down
Loading