4 ms·
Are transducers necessary in Clojure because functions of function of functions (etc...) on immutable data structures execute slowly?
by jgalt212 11y ago
Are transducers necessary in Clojure because functions of function of functions (etc...) on immutable data structures execute slowly?
- harlanji 11y agoThey help relieve pressure on the garbage collector by eliminating intermediate sequence allocations (eg. (comp (map a) (map b) (filter c) (map d)) would create 4 sequences, transducers create none). Consequently you can work with results incrementally unless there is an intermediate flush required such as for a windowed aggregation. I imagine most applications aren't very sensitive to the performance gain, but it's good to know for when you need it. In addition it's a nice and testable, compos-able pattern. I've only done backend work, no cljs yet, but I'd call it reasonable practice to think in terms of compositions/transducers for most data transformation pipelines in the future though, throughout the stack, whether performance matters or not.