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 5 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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* `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)

Wrong number!

Perhaps this and #818 can be one release.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW I don't have merge rights here. This may need a rebase after #818 is in, before tagging.


* `@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)
Expand Down
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 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 # 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))
@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