JuliaFolds / Transducers.jl

Efficient transducers for Julia
https://juliafolds.github.io/Transducers.jl/dev/
MIT License
433 stars 24 forks source link

SplitBy followed by another SplitBy? #549

Open tk3369 opened 1 year ago

tk3369 commented 1 year ago

I'm not able to using SplitBy after another SplitBy without using collect in between. I just want to know if this is by design?


julia> xs = [1, 2, 3, 0, 1, 2, 3, 4, 0, 0, 1, 2, 5];  # input

julia> xs |> SplitBy(iszero) |> collect
3-element Vector{SubArray{Int64, 1, Vector{Int64}, Tuple{UnitRange{Int64}}, true}}:
 [1, 2, 3]
 [1, 2, 3, 4]
 [1, 2, 5]

julia> xs |> SplitBy(iszero) |> SplitBy(==(2))
ERROR: MethodError: no method matching keys(::Transducers.Eduction{Transducers.Reduction{Transducers.ReduceSplitBy{Transducers.var"#91#92"{SplitBy{typeof(iszero), Val{false}, Val{false}}, Vector{Int64}}, Transducers.SplitByReducingFunction{Val{false}, Val{false}}, Nothing}, Transducers.Reduction{NotA{Nothing}, Transducers.Reduction{Map{Transducers.var"#view_any#93"{Vector{Int64}}}, Transducers.BottomRF{Completing{typeof(push!!)}}}}}, Base.OneTo{Int64}})
Closest candidates are:
  keys(::Union{Tables.AbstractColumns, Tables.AbstractRow}) at ~/.julia/packages/Tables/T7rHm/src/Tables.jl:189
  keys(::Base.Generator) at generator.jl:54
  keys(::OrderedCollections.OrderedSet) at ~/.julia/packages/OrderedCollections/PRayh/src/ordered_set.jl:95
  ...
Stacktrace:
 [1] eachindex(itrs::Transducers.Eduction{Transducers.Reduction{Transducers.ReduceSplitBy{Transducers.var"#91#92"{SplitBy{typeof(iszero), Val{false}, Val{false}}, Vector{Int64}}, Transducers.SplitByReducingFunction{Val{false}, Val{false}}, Nothing}, Transducers.Reduction{NotA{Nothing}, Transducers.Reduction{Map{Transducers.var"#view_any#93"{Vector{Int64}}}, Transducers.BottomRF{Completing{typeof(push!!)}}}}}, Base.OneTo{Int64}})
   @ Base ./abstractarray.jl:282
 [2] |>(x::Transducers.Eduction{Transducers.Reduction{Transducers.ReduceSplitBy{Transducers.var"#91#92"{SplitBy{typeof(iszero), Val{false}, Val{false}}, Vector{Int64}}, Transducers.SplitByReducingFunction{Val{false}, Val{false}}, Nothing}, Transducers.Reduction{NotA{Nothing}, Transducers.Reduction{Map{Transducers.var"#view_any#93"{Vector{Int64}}}, Transducers.BottomRF{Completing{typeof(push!!)}}}}}, Base.OneTo{Int64}}, f::typeof(eachindex))
   @ Base ./operators.jl:911
 [3] (::SplitBy{Base.Fix2{typeof(==), Int64}, Val{false}, Val{false}})(xs::Transducers.Eduction{Transducers.Reduction{Transducers.ReduceSplitBy{Transducers.var"#91#92"{SplitBy{typeof(iszero), Val{false}, Val{false}}, Vector{Int64}}, Transducers.SplitByReducingFunction{Val{false}, Val{false}}, Nothing}, Transducers.Reduction{NotA{Nothing}, Transducers.Reduction{Map{Transducers.var"#view_any#93"{Vector{Int64}}}, Transducers.BottomRF{Completing{typeof(push!!)}}}}}, Base.OneTo{Int64}})
   @ Transducers ~/.julia/packages/Transducers/iubDU/src/splitby.jl:267
 [4] |>(x::Transducers.Eduction{Transducers.Reduction{Transducers.ReduceSplitBy{Transducers.var"#91#92"{SplitBy{typeof(iszero), Val{false}, Val{false}}, Vector{Int64}}, Transducers.SplitByReducingFunction{Val{false}, Val{false}}, Nothing}, Transducers.Reduction{NotA{Nothing}, Transducers.Reduction{Map{Transducers.var"#view_any#93"{Vector{Int64}}}, Transducers.BottomRF{Completing{typeof(push!!)}}}}}, Base.OneTo{Int64}}, f::SplitBy{Base.Fix2{typeof(==), Int64}, Val{false}, Val{false}})
   @ Base ./operators.jl:911
 [5] top-level scope
   @ REPL[120]:1
MasonProtter commented 1 year ago

Seems like a bug, probably a missing method somewhere, I'll try to look into it soon.

rickbeeloo commented 1 year ago

@MasonProtter isn't this because the second SplitBy would actually receive the subarray, not the individual elements? Is @tkf not working on this any more?