length for iterators

This commit is contained in:
Mike J Innes 2016-10-30 01:18:20 +01:00
parent ce0cde0d2b
commit 4d45ee1bb9

View File

@ -9,6 +9,8 @@ import Iterators: partition
export partition export partition
Base.length(l::Iterators.Partition) = length(l.xs) ÷ l.step
_partition(r::UnitRange, step::Integer) = (step*(i-1)+1:step*i for i in 1:(r.stop÷step)) _partition(r::UnitRange, step::Integer) = (step*(i-1)+1:step*i for i in 1:(r.stop÷step))
_partition(xs, step) = (xs[i] for i in _partition(1:length(xs), step)) _partition(xs, step) = (xs[i] for i in _partition(1:length(xs), step))