Folds.jl
Folds.jl copied to clipboard
Add single-argument version of Folds.reduce?
Would be handy to be able to write
Filter(isodd) ⨟ MapCat(x -> 1:x^2) ⨟ Folds.reduce(+)
instead of
Filter(isodd) ⨟ MapCat(x -> 1:x^2) ⨟ (x -> Folds.reduce(+, x))
Or would a single-argument Folds.reduce
break some concepts behind Folds
?
Thanks for the suggestion! There's actually a "secrete" function Transducers.fold
that does this. But I'm not sure about the API so it's currently not a public API.
The main reasons why I'm a bit hesitant for implementing this are that:
- If I go to this direction, I'd like to support
xs |> Folds.reduce(op, executor)
forFolds.reduce(op, xs, executor)
, too. - But, if I do it, it's hard to decide what
Folds.reduce(a, b)
would do without knowing the type ofb
.
Maybe the best way forward to add reducewith(op, [executor])
function, like mergewith
in Base
.
Oh, yes.
Just an idea - how about using Folds.reduce(op, executor = default_exec)(xs)
as a syntax instead, so that Folds.reduce(op, executor = default_exec)
becomes a functional, semantically, just like Folds.sum
?
Actually, how does one currently set the executor for Folds.sum
& friends?