| ▲ | fud101 3 hours ago | |||||||
Thanks. So is this not an optimiser Clojure runtime can do for you automatically? I find the first one simpler to read and understand. | ||||||||
| ▲ | jwr 3 hours ago | parent [-] | |||||||
Performance is one of the niceties of transducers, but the real benefits are from better code abstractions. For example, transducers decouple the collection type from data-processing functions. So you can write (into #{} ...) (a set), (into [] ...) (a vector) or (into {} ...) (a map) — and you don't have to modify the functions that process your data, or convert a collection at the end. The functions don't care about your target data structure, or the source data structure. They only care about what they process. The fact that no intermediate structures have to be created is an additional nicety, not really an optimization. It is true that for simple examples the (-> ...) is easier to read and understand. But you get used to the (into) syntax quickly, and you can do so much more this way (composable pipelines built on demand!). | ||||||||
| ||||||||