Skip to content

Commit dc78cd9

Browse files
authored
fix last(::Enumerate) when indexing not supported (#59226)
1 parent e4a3a2a commit dc78cd9

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

base/iterators.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ size(e::Enumerate) = size(e.itr)
198198
n === nothing && return n
199199
(i, n[1]), (i+1, n[2])
200200
end
201-
last(e::Enumerate) = (length(e.itr), e.itr[end])
201+
last(e::Enumerate) = (length(e.itr), last(e.itr))
202202

203203
eltype(::Type{Enumerate{I}}) where {I} = TupleOrBottom(Int, eltype(I))
204204

test/iterators.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1070,6 +1070,7 @@ end
10701070
@testset "last for iterators" begin
10711071
@test last(Iterators.map(identity, 1:3)) == 3
10721072
@test last(Iterators.filter(iseven, (Iterators.map(identity, 1:3)))) == 2
1073+
@test last(enumerate(Iterators.flatten((1,2,3)))) == (3,3)
10731074
end
10741075

10751076
@testset "isempty and isdone for Generators" begin

0 commit comments

Comments
 (0)