Does transduce take its arguments in the wrong order?
See original GitHub issueI realized something yesterday about transduce
that has bothered me for a long time. Every time I use it I pretty much make a custom transducer function but the accumulator function and the initial argument pretty much only varies in two ways.
- Case 1: I build up a list of elements where xf is
flip(append)
and acc is[]
- Case 2: I build up a sum where xf is
add
and acc is0
Because of this, it seems a better argument order would be transduce(xf, acc, transducer, list)
. With this I could create
transduceToList = transduce(flip(append), [])
transduceToSum = transduce(add, 0)
I suspect that other uses of transduce
would follow the same pattern.
I realize that transduce
is not a ramda invention and that it probably follows a format from somewhere else. I just wanted to bring this up for discussion.
Issue Analytics
- State:
- Created 7 years ago
- Reactions:1
- Comments:7 (6 by maintainers)
Top Results From Across the Web
Transducers: sequence versus eduction - Google Groups
Transducers make different trade offs than sequences and there will always be cases where one or the other is a better choice. I...
Read more >Understanding transducers - Andrey Listopadov
First, a bit of theory. A transducer is a function that describes the process of transformation, without knowing how exactly the thing it...
Read more >Clojure transducers behavior - Stack Overflow
1 Answer 1 · Yes, xf == xform is a "transducer". · Your my-identity function does not compile. · Your argument to your...
Read more >Transduce does more work than necessary · Issue #1792 · ramda ...
Hi @cristianocd ,. You're transducer is mapping before it is taking. See eg #1790. You can either change the order of your arguments...
Read more >Grokking Clojure transducers - /dev/solita
In essence, a transducer is a function that takes a reducing function (like conj ) and turns it into a new, more awesome...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Yes, this is the expected behavior. There are several good articles, mostly Clojure related:
I’m having problem in understanding something kinda related to “order”. I’m using R.into with a composed transducer but the order of the functions calls inside R.compose is the opposite (left to right), like pipe, and vice-versa: using R.pipe the functions are called from right to left. https://goo.gl/ZuKUvN
Is this the expected behaviour?