什么是Clojure相当于Scala的zipWithIndex?

Chr*_*tin 2 clojure

Scala Seq有这样的zipWithIndex方法:

def zipWithIndex[A1 >: A, That](implicit bf: CanBuildFrom[Seq[A], (A1, Int), That]): That

用它的索引来拉开这个序列.

返回:包含由该序列的所有元素组成的对的新序列与其索引配对.指数从0开始.

例: List("a", "b", "c").zipWithIndex = List(("a", 0), ("b", 1), ("c", 2))

Clojure中的等效函数是什么?

jma*_*svt 7

Clojure map-indexed将为您提供集合中元素的索引列表.

user=> (map-indexed vector "foo")
([0 \f] [1 \o] [2 \o])
Run Code Online (Sandbox Code Playgroud)