在此博客条目中,CSP和JavaScript中的传感器,作者指出:
In this blog entry, "CSP and transducers in JavaScript", the author states:
首先,我们必须意识到许多数组(或其他集合)操作,如 ,过滤器和 reverse 可以根据 reduce 。
所以然后我们看到 Clojure中的一些实现不是懒惰,他们是渴望的:
So then we see a number of implementations of this in Clojure aren't lazy, they are eager:
user> (defn eager-map [f coll] (reduce (fn [acc v] (conj acc (f v))) [] coll)) #'user/eager-map user> (eager-map inc (range 10)) [1 2 3 4 5 6 7 8 9 10]我的问题是,Clojure传感器是否渴望?
My question is, are Clojure transducers eager?
推荐答案传感器是非常简单的功能 - 他们没有一个懒惰的概念,实际上它们是如何应用的。这就是这个想法的美丽 - 通过传感器,我们可以从它们的内容中分离出诸如 map 和 filter 的函数
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.
更多推荐
Clojure传感器是否渴望?
发布评论