Skip to content

Commit 55fd848

Browse files
author
Arda Aytekin
committed
Import Base.eachindex for overloading
Closes #118.
1 parent 909ea47 commit 55fd848

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

src/Polynomials.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export degree, coeffs, variable
1212
export polyval, polyint, polyder, roots, polyfit
1313
export Pade, padeval
1414

15-
import Base: start, next, done, length, size, eltype, collect
15+
import Base: start, next, done, length, size, eltype, collect, eachindex
1616
import Base: endof, getindex, setindex!, copy, zero, one, convert, norm, gcd
1717
import Base: show, print, *, /, //, -, +, ==, isapprox, divrem, div, rem, eltype
1818
import Base: promote_rule, truncate, chop, conj, transpose, dot, hash
@@ -286,7 +286,7 @@ end
286286

287287
setindex!(p::Poly, values, ::Colon) = setindex!(p, values, 0:length(p)-1)
288288

289-
eachindex{T}(p::Poly{T}) = 0:(length(p)-1)
289+
eachindex(p::Poly) = 0:degree(p)
290290

291291
copy(p::Poly) = Poly(copy(p.a), p.var)
292292

test/runtests.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,3 +339,5 @@ end
339339
@test_throws InexactError collect(Poly{Int}, Poly([1.2]))
340340

341341
@test length(collect(p1)) == degree(p1)+1
342+
343+
@test [p1[idx] for idx in eachindex(p1)] == [1,2,0,3]

0 commit comments

Comments
 (0)