Are Clojure transducers eager?

后端 未结 1 1294
借酒劲吻你
借酒劲吻你 2021-01-18 08:37

In this blog entry, \"CSP and transducers in JavaScript\", the author states:

First, we have to realise that many array (or other collection) operatio

相关标签:
1条回答
  • 2021-01-18 09:19

    Transducers are very simple functions - they don't have a notion of laziness or, in fact, how they're applied at all. That's the beauty of the idea - with transducers, we can separate functions like map and filter from the things on which they operate.

    So, yes, they can be used to build lazy sequences, as well as channels and reductions. While the transducer function call itself is eager, it's up to whatever thing you hand the transducer to to call it. Lazy sequences can lazily invoke transducers only as they're consumed while reducers will use them eagerly to spit out the reduction.

    You can see in the source where sequence is used to build a lazy sequence over a collection with a transducer.

    0 讨论(0)
提交回复
热议问题