Clojure传感器是否渴望?

编程入门 行业动态 更新时间:2024-10-21 03:52:11
本文介绍了Clojure传感器是否渴望?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

在此博客条目中,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传感器是否渴望?

本文发布于:2023-11-23 20:49:16,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1622822.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:传感器   Clojure

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!