From 1218955826edf45445839b86c299f44ff9357fc6 Mon Sep 17 00:00:00 2001 From: Michael Abbott <32575566+mcabbott@users.noreply.github.com> Date: Sun, 11 Feb 2024 20:04:40 -0500 Subject: [PATCH 1/6] Iterators.cycle(iter, n) --- src/Compat.jl | 5 +++++ test/runtests.jl | 18 ++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/src/Compat.jl b/src/Compat.jl index c8bb90f24..9ca70b3e2 100644 --- a/src/Compat.jl +++ b/src/Compat.jl @@ -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 VERION < v"1.11-" # e6992f74b003eead40d928a31e1c5baaba79f377 + Iterators.cycle(xs, n::Integer) = Iterators.flatten(Iterators.repeated(xs, n)) +end + include("deprecated.jl") end # module Compat diff --git a/test/runtests.jl b/test/runtests.jl index 2b6e95ceb..fde24f40b 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -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 From 41a77c8d2e33c9551079185dd57adde7a7e9ab1f Mon Sep 17 00:00:00 2001 From: Michael Abbott <32575566+mcabbott@users.noreply.github.com> Date: Tue, 13 Feb 2024 08:40:42 -0500 Subject: [PATCH 2/6] Update src/Compat.jl Co-authored-by: Martin Holters --- src/Compat.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Compat.jl b/src/Compat.jl index 9ca70b3e2..079c250ac 100644 --- a/src/Compat.jl +++ b/src/Compat.jl @@ -776,7 +776,7 @@ if VERSION < v"1.9.0-DEV.461" end # https://github.com/JuliaLang/julia/pull/47354 -if VERION < v"1.11-" # e6992f74b003eead40d928a31e1c5baaba79f377 +if VERSION < v"1.11.0-DEV.1579" Iterators.cycle(xs, n::Integer) = Iterators.flatten(Iterators.repeated(xs, n)) end From de0d4317af5fe03f53a89f4194a4e592bf157c94 Mon Sep 17 00:00:00 2001 From: Michael Abbott <32575566+mcabbott@users.noreply.github.com> Date: Tue, 13 Feb 2024 09:12:51 -0500 Subject: [PATCH 3/6] Update test/runtests.jl --- test/runtests.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/runtests.jl b/test/runtests.jl index fde24f40b..6ba495ae1 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -737,7 +737,7 @@ end # https://github.com/JuliaLang/julia/pull/47354 @testset "cycle(iter, n)" begin - using Iterators: cycle + using Base.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 From 45f9d12098f44f944a6c756d31ea51e3f7588b1b Mon Sep 17 00:00:00 2001 From: Michael Abbott <32575566+mcabbott@users.noreply.github.com> Date: Tue, 13 Feb 2024 13:13:51 -0500 Subject: [PATCH 4/6] Update test/runtests.jl --- test/runtests.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/runtests.jl b/test/runtests.jl index 6ba495ae1..b2c259513 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -740,7 +740,7 @@ end using Base.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 collect(take(cycle(countfrom(11), 3), 4)) == 11:14 # this iterator is defined in Base's tests @test isempty(cycle(1:0)) == isempty(cycle(1:0, 3)) == true @test isempty(cycle(1:5, 0)) From d779ff9feb60873b294ab992592c537cd660a13b Mon Sep 17 00:00:00 2001 From: Michael Abbott <32575566+mcabbott@users.noreply.github.com> Date: Wed, 14 Feb 2024 09:53:09 -0500 Subject: [PATCH 5/6] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 126df2a8c..5c6888e63 100644 --- a/README.md +++ b/README.md @@ -70,6 +70,8 @@ changes in `julia`. ## Supported features +* `Iterators.cycle(itr, n)` is the lazy version of `repeat(vector, n)`. ([#47354]) (since Compat 4.12.0) + * `@compat public foo, bar` marks `foo` and `bar` as public in Julia 1.11+ and is a no-op in Julia 1.10 and earlier. ([#50105]) (since Compat 3.47.0, 4.10.0) * `redirect_stdio`, for simple stream redirection. ([#37978]) (since Compat 4.8.0) From fba789aa3bd7011dba94e82264437935f285fa79 Mon Sep 17 00:00:00 2001 From: Michael Abbott <32575566+mcabbott@users.noreply.github.com> Date: Wed, 14 Feb 2024 09:54:53 -0500 Subject: [PATCH 6/6] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 5c6888e63..c023026ba 100644 --- a/README.md +++ b/README.md @@ -70,7 +70,7 @@ changes in `julia`. ## Supported features -* `Iterators.cycle(itr, n)` is the lazy version of `repeat(vector, n)`. ([#47354]) (since Compat 4.12.0) +* `Iterators.cycle(itr, n)` is the lazy version of `repeat(vector, n)`. ([#47354]) (since Compat 4.13.0) * `@compat public foo, bar` marks `foo` and `bar` as public in Julia 1.11+ and is a no-op in Julia 1.10 and earlier. ([#50105]) (since Compat 3.47.0, 4.10.0)