more robust batches
This commit is contained in:
parent
65400f20ab
commit
358ba650ad
@ -1,4 +1,10 @@
|
||||
import Base: start, next, done, iteratorsize, iteratoreltype, eltype, length
|
||||
# Simple version
|
||||
|
||||
using Base.Iterators: partition
|
||||
|
||||
partitionr(xs, n) = take(partition(xs, n), length(xs)÷n)
|
||||
|
||||
batches(xs, n) = (Batch([xs...]) for xs in partitionr(xs, n))
|
||||
|
||||
# Stateful iteration
|
||||
|
||||
@ -40,6 +46,8 @@ end
|
||||
|
||||
# Batched
|
||||
|
||||
import Base: start, next, done, iteratorsize, iteratoreltype, eltype, length
|
||||
|
||||
struct Batched{I<:StatefulIter,S}
|
||||
itr::I
|
||||
buf::S
|
||||
|
Loading…
Reference in New Issue
Block a user