From 45c2dff902eaa05fed07cc01c6cfe92826f7b72f Mon Sep 17 00:00:00 2001 From: Andreas Theodosiou Date: Mon, 6 May 2024 14:56:06 +0200 Subject: [PATCH] Add split_into_chunks for ProgressLoggingFoldable * Calling collect on a Foldable that is wrapped with withprogress to allow progress logging fails because ProgressLoggingFoldable is not iterable. * We add a method of split_into_chunks for when coll is a ProgressLoggingFodlable that partitions the foldable enclosed withing the ProgressLoggingFoldable struct, collects it, and then rewraps with a call to withprogress to allow logging to continue. * This allows the creation of transducers with progress logging and fixes JuliaFolds2/Transduces.jl#10 --- src/progress.jl | 1 + src/reduce.jl | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/src/progress.jl b/src/progress.jl index b2eb316f..1dacc8ba 100644 --- a/src/progress.jl +++ b/src/progress.jl @@ -60,6 +60,7 @@ end Base.IteratorSize(::Type{ProgressLoggingFoldable{T}}) where {T} = Base.IteratorSize(T) Base.IteratorEltype(::Type{ProgressLoggingFoldable{T}}) where {T} = Base.IteratorEltype(T) Base.length(foldable::ProgressLoggingFoldable) = length(foldable.foldable) +Base.size(foldable::ProgressLoggingFoldable) = size(foldable.foldable) Base.eltype(::Type{ProgressLoggingFoldable{T}}) where {T} = eltype(T) # Use Juno/Atom-compatible log-level. See: diff --git a/src/reduce.jl b/src/reduce.jl index 60be6202..a38b8bdc 100644 --- a/src/reduce.jl +++ b/src/reduce.jl @@ -353,6 +353,10 @@ function split_into_chunks(coll, sz) collect(Iterators.partition(coll, sz)) end +function split_into_chunks(coll::Transducers.ProgressLoggingFoldable, sz) + withprogress(collect(Iterators.partition(coll.foldable, sz)); interval=coll.interval) +end + tcopy(xf, reducible; kwargs...) = tcopy(xf, _materializer(reducible), reducible; kwargs...) function tcopy(::Type{T}, itr; kwargs...) where {T}