From 1bb509f5bf629fb2e1ff89bf66f0d0467b2b1ab1 Mon Sep 17 00:00:00 2001 From: KristofferC Date: Thu, 19 Oct 2023 14:31:02 +0200 Subject: [PATCH] fix eltype for partition iterators of substrings --- base/strings/util.jl | 2 ++ test/iterators.jl | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/base/strings/util.jl b/base/strings/util.jl index 890afaf62b2ee..db4e7917c009e 100644 --- a/base/strings/util.jl +++ b/base/strings/util.jl @@ -571,6 +571,8 @@ end # Specialization for partition(s,n) to return a SubString eltype(::Type{PartitionIterator{T}}) where {T<:AbstractString} = SubString{T} +# SubStrings do not nest +eltype(::Type{PartitionIterator{T}}) where {T<:SubString} = T function iterate(itr::PartitionIterator{<:AbstractString}, state = firstindex(itr.c)) state > ncodeunits(itr.c) && return nothing diff --git a/test/iterators.jl b/test/iterators.jl index 59588bdac9684..a60ec32bb9ac0 100644 --- a/test/iterators.jl +++ b/test/iterators.jl @@ -1001,3 +1001,7 @@ end end @test v == () end + +@testset "collect partition substring" begin + @test collect(Iterators.partition(lstrip("01111", '0'), 2)) == ["11", "11"] +end