Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
5 changes: 5 additions & 0 deletions src/Compat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -775,6 +775,11 @@ if VERSION < v"1.9.0-DEV.461"
Base.VersionNumber(v::VersionNumber) = v
end

# https://github.com/JuliaLang/julia/pull/47354
if VERSION < v"1.11.0-DEV.1579"
Iterators.cycle(xs, n::Integer) = Iterators.flatten(Iterators.repeated(xs, n))
end

include("deprecated.jl")

end # module Compat
18 changes: 18 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -734,3 +734,21 @@ end
v = VersionNumber("1.2.3")
@test VersionNumber(v) === v
end

# https://github.com/JuliaLang/julia/pull/47354
@testset "cycle(iter, n)" begin
using Iterators: cycle
@test collect(cycle(0:3, 2)) == [0, 1, 2, 3, 0, 1, 2, 3]
@test collect(cycle(Iterators.filter(iseven, 1:4), 2)) == [2, 4, 2, 4]
@test collect(take(cycle(countfrom(11), 3), 4)) == 11:14

@test isempty(cycle(1:0)) == isempty(cycle(1:0, 3)) == true
@test isempty(cycle(1:5, 0))
@test isempty(cycle(Iterators.filter(iseven, 1:4), 0))

@test eltype(cycle(0:3, 2)) === Int
@test Base.IteratorEltype(cycle(0:3, 2)) == Base.HasEltype()

Base.haslength(cycle(0:3, 2)) == false # but not sure we should test these
Base.IteratorSize(cycle(0:3, 2)) == Base.SizeUnknown()
end