函数 seq?、sequential 之间有什么区别?和科尔? [英] What is the difference between the functions seq?, sequential? and coll?
问题描述
函数seq有什么区别?顺序?和科尔?
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
接口,则返回 true,也就是说它提供了方法first
、rest
、cons
.请参阅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?
是一个谓词,如果它的参数实现了 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?
是一个谓词,如果其参数实现了 IPersistentCollection
,则返回 true.例如,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?、sequential 之间有什么区别?和科尔?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!