Skip to content

Commit

Permalink
Add into(T, xf, foldable)
Browse files Browse the repository at this point in the history
  • Loading branch information
tkf committed Nov 5, 2019
1 parent 9269c21 commit 12234f5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Transducers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ export Transducer, Map, Filter, Cat, MapCat, Take, PartitionBy, Scan, Zip,
TakeLast, FlagFirst, MapSplat, ScanEmit, Enumerate, NotA, OfType,
transduce, eduction, setinput, Reduced, reduced, unreduced, ifunreduced,
Completing, OnInit, CopyInit, right, reducingfunction, dreduce, dtransduce,
withprogress, AdHocFoldable
withprogress, AdHocFoldable, into

# Deprecated:
export Distinct

using Base.Broadcast: Broadcasted

using ArgCheck
using BangBang: BangBang, empty!!, push!!, setindex!!
using BangBang: BangBang, Empty, empty!!, push!!, setindex!!
using Distributed: Distributed, @everywhere
using Logging: LogLevel, @logmsg
using Requires
Expand Down
12 changes: 12 additions & 0 deletions src/processes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,18 @@ function Base.collect(xf::Transducer, coll)
end
# Base.collect(xf, coll) = append!([], xf, coll)

"""
into(T, xf, foldable) :: Union{T, Nothing}
"""
function into(::Type{T}, xf::Transducer, coll) where T
rf = Reduction(xf, Completing(push!!))
result = unreduced(transduce(rf, Empty(T), coll))
if result isa Empty
return nothing
end
return result
end

"""
map!(xf::Transducer, dest, src; simd)
Expand Down

0 comments on commit 12234f5

Please sign in to comment.