Skip to content

Commit e2a0bfc

Browse files
committed
use collect/take instead of iterate
1 parent 099c18e commit e2a0bfc

File tree

1 file changed

+2
-14
lines changed

1 file changed

+2
-14
lines changed

src/Primes.jl

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -716,8 +716,7 @@ julia> nextprimes(10, 3)
716716
17
717717
```
718718
"""
719-
nextprimes{T<:Integer}(start::T, n::Integer) =
720-
iterate(x->nextprime(add(x, 1)), nextprime(start), n)
719+
nextprimes{T<:Integer}(start::T, n::Integer) = collect(T, take(nextprimes(start), n))
721720

722721
immutable PrevPrimes{T<:Integer}
723722
start::T
@@ -767,17 +766,6 @@ julia> prevprimes(10, 3)
767766
3
768767
```
769768
"""
770-
prevprimes{T<:Integer}(start::T, n::Integer) =
771-
iterate(x->prevprime(add(x, -1)), prevprime(start), n)
772-
773-
function iterate(f, x, n::Integer)
774-
v = Vector{eltype(x)}(n)
775-
n != 0 && (@inbounds v[1] = x)
776-
@inbounds for i = 2:n
777-
x = f(x)
778-
v[i] = x
779-
end
780-
v
781-
end
769+
prevprimes{T<:Integer}(start::T, n::Integer) = collect(T, take(prevprimes(start, n)))
782770

783771
end # module

0 commit comments

Comments
 (0)