Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Iterators.cycle(iter, n) #819

Merged
merged 6 commits into from
Feb 16, 2024
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
mcabbott marked this conversation as resolved.
Show resolved Hide resolved
@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
mcabbott marked this conversation as resolved.
Show resolved Hide resolved

@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
Loading