顺序函数seq?有什么区别?和科尔? [英] What is the difference between the functions seq?, sequential? and coll?

查看:113
本文介绍了顺序函数seq?有什么区别?和科尔?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

seq函数之间有什么区别?顺序的?和coll?

What is the difference between the functions seq? sequential? and coll?

我发现一些信息散布在整个互联网上,但是我认为最好在此处集中这些信息。

I found some information scattered throughout the internet, but I think it would be better to centralize that information here.

推荐答案

seq?是一个谓词,如果其参数实现 ISeq 接口,也就是说它提供了 first rest 方法缺点。请参见 http://clojure.org/sequences

seq? is a predicate that returns true if it's argument implements ISeq interface, which is to say it provides the methods first,rest,cons. See http://clojure.org/sequences.

(seq? [1 2])
false
(seq? (seq [1 2]))
true

顺序?是一个谓词,如果其参数实现 Sequential 接口,则返回true。 Sequential 是一个标记接口(无方法),并保证可以按定义的顺序(例如列表,但不映射)对集合进行迭代。

sequential? is a predicate that returns true if it's argument implements Sequential interface. Sequential is a marker interface (no methods) and is a promise that the collection can be iterated over in a defined order (e.g. a list, but not a map).

(sequential? [])
true
(sequential? {})
false

coll?是一个谓词,如果其返回值是true参数实现 IPersistentCollection 。因此,例如clojure数据结构将返回true,而本机java数据结构将不会:

coll? is a predicate that returns true if its argument implments IPersistentCollection. So for example the clojure data structures would return true, whereas native java data structures would not:

(coll? {:a 1})
true
(coll? (java.util.HashMap.))
false

这篇关于顺序函数seq?有什么区别?和科尔?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆