Skip to content

Commit b139e7f

Browse files
author
Michael Abbott
committed
add Index[begin] on 1.4
1 parent 0341b2f commit b139e7f

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

src/selectors.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,10 @@ Base.lastindex(::Type{Index}) = LastIndex()
7070
Index(::LastIndex) = LastIndex()
7171

7272
findindex(sel::LastIndex, range::AbstractArray) = lastindex(range)
73+
74+
if VERSION >= v"1.4" # same thing for Index[begin]
75+
struct FirstIndex <: Selector{Int} end
76+
Base.firstindex(::Type{Index}) = FirstIndex()
77+
Index(::FirstIndex) = FirstIndex()
78+
findindex(sel::FirstIndex, range::AbstractArray) = firstindex(range)
79+
end

test/_basic.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ end
6565
@test V(Index[1]) == V[1]
6666
@test V(Index[2:3]) == V[2:3]
6767
@test V(Index[end]) == V[end]
68+
if VERSION >= v"1.4"
69+
@test V(Index[begin]) == V[1]
70+
end
6871

6972
V2 = wrapdims(rand(Int8, 5), [1,2,3,2,1])
7073
@test V2(==(2)) == V2[[2,4]]

0 commit comments

Comments
 (0)