Skip to content

Commit

Permalink
fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
mcabbott committed Oct 27, 2022
1 parent bf72c3d commit ba31505
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion base/iterators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -946,7 +946,7 @@ true
```
"""
cycle(xs) = Cycle(xs)
cycle(xs, n::Int) = flatten(repeated(xs, n))
cycle(xs, n::Integer) = flatten(repeated(xs, n))

eltype(::Type{Cycle{I}}) where {I} = eltype(I)
IteratorEltype(::Type{Cycle{I}}) where {I} = IteratorEltype(I)
Expand Down
7 changes: 6 additions & 1 deletion test/iterators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,13 @@ let i = 0
end

@testset "cycle(iter, n)" begin
@test cycle(0:3, 2) == [0, 1, 2, 3, 0, 1, 2, 3]
@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()
Expand Down

0 comments on commit ba31505

Please sign in to comment.