- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在 Clojure 中有一个名为 mapcat 的函数在 Clojure 中,它与 flatmap in Scala 有一些相似之处.是used to map a function to a list并返回一个列表。
在 Haskell 中,我们有一个函数 ConcatMap其名seems quite similar .
我的问题是 - Clojure 中的 mapcat 和 Haskell 中的 concatmap 有什么区别?
最佳答案
concatMap
在 Haskell 中有类型 concatMap :: (a -> [b]) -> [a] -> [b]
而 Clojure 的 mapcat
,如果它有任何类型,就必须复杂得多。初步近似,我们可以写
mapcat :: (Collection c, Collection c') => (a -> c' b) -> c a -> [b]
mapCat
继承
map
的动态参数列表,因此根本无法在 Haskell 中输入,但如果可以,它可能看起来像
mapcat :: (forall c . Collection c => a -> ... -> c b)
-> [forall c . Collection c => c a]
-> [b]
mapCat
可能是,尽管仍然不如实际动态。也就是说,如果我们 promise 只将一个惰性序列传递给
mapcat
那么它与
concatMap
相同并且具有几乎完全相同的代码
concatMap f s = concat (map f s)
(defn mapcat [f coll] (concat (map f coll)))
concatMap
,他们使用
(>>=)
(或列表推导式,如果需要,可以翻译成
(>>=)
)。
-- flipped for consistency
flip (>>=) :: Monad m => (a -> m b) -> m a -> m b
(>>=)
输入的多态性仍然低于
mapcat
,但是
(>>=)
也是输出多态。这使它具有更多的语义多样性。您并不总是从集合中提取值,将答案压缩到结果列表中,然后将这些结果粘合在一起。相反,您可能会将延续函数传递到非确定性并行编排过程中。或者排序解析器,其中第二个依赖于第一个的输出。或者传播一个有状态的环境。
关于haskell - Clojure 中的 mapcat 和 Haskell 中的 concatmap 有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20782258/
是否可以并行执行高阶可观察对象,但在合并结果时仍保留顺序? 我有这样的东西: invoker$: Observable; fetch: (index: number) => Observable; i
我有这个设置: public listenCampaignSelected(){ var campaignSelected$ = this.store .select(store => s
这个问题在这里已经有了答案: Difference between concatMap f xs and concat $ map f xs? (1 个回答) 7年前关闭。 concatMap 是什么
我正在处理一组文件。对于每个文件,我需要请求正确的上传 URL,然后将该文件上传到正确的端点。 concatMap应该仅在前一个值完成后发出。这样,文件就应该被顺序处理。 这是我的代码: filesC
问题 7 来自 99 个 Haskell 问题 展平嵌套列表结构 这是我的解决方案: data NestedList a = Elem a | List [NestedList a] myFlatte
我有一个 37MB bin 文件,我正在尝试将其转换为 ppm 序列。它工作正常,我正在尝试将其用作练习来学习一些分析以及有关 Haskell 中惰性字节串的更多信息。我的程序似乎在 concatMa
我有以下代码: Observable.from(modifiedNodes) .concatMap(node => { return this.Model.setData(no
这个问题已经有答案了: Replace a 3 parameter list-comprehension by using map, concat (3 个回答) 已关闭 3 年前。 如何将列表理解转
我总体上很困惑,并正在寻找关于此代码如何工作的非常详细和解释性的答案: let xs = [1] ++ concatMap (\x -> [x+1,x*10]) xs in xs concatMap
这个问题已经有答案了: Replace a 3 parameter list-comprehension by using map, concat (3 个回答) 已关闭 3 年前。 如何将列表理解转
我在玩>>=今天,试图了解monads,发现了一个有趣的模式。使用列表单子(monad)时,>>=似乎表现得像 concatMap。我四处搜寻,试图找到任何相似之处,特别是在 hackage 的定义中
我试图找到一个行为类似于 concatMap 的运算符,但会丢弃介于两者之间的所有内容。例如, concatMap 执行以下操作: next a start handling a next b nex
可能是一个基本问题,但我有一个 Angular 应用程序调用后端服务来检索一些数据,然后使用该数据进行另一个后端服务调用。 第二次服务调用依赖于第一次成功完成,所以我使用 RxJS 的 concatM
我一直没能找到这个问题的答案,但是 concat map 之间有什么区别?和 map ?具体来说,我有一个让我很困惑的例子: const domainsObservable = this.auth.g
在Stream中我们可以通过flatMap将多维数据打开降维,扁平化处理数据为一维数据。Reactor当然也有这种需求,我们可以使用flatMap和concatMap进行数据的降维处理 flatMap
我读自Foldr Foldl Foldl'由于严格属性,foldl' 对于长的有限列表更有效。我知道它不适合无限列表。 因此,我只对长的有限列表进行比较。 连接映射 concatMap是使用 fold
考虑这个例子:我有一个文件按顺序下载。如果一个下载失败,它应该移动到下一个。伪代码: Observable.from(urls) .concatMap(url -> downloadObservab
我有一个 Observable 链和一个对话框,在一切都完成后会消失。顺序是这样的:1 api调用获取ResponseBody2 取response body进程(非ui线程)3个其他进程(不是ui线
我有 2 个 retrofit 电话需要进行 A 和 B: (A):返回一个ArrayList (B):获取 (A) 的结果,它是一个 ArrayList。 (B) 遍历 ArrayList 并使用每
我用 concatMap以长时间运行的操作一次处理一个项目流。在某些时候,我需要“中断”这个长时间运行的操作,但仅限于当前项目: @Test public void main() throws Int
我是一名优秀的程序员,十分优秀!