gpt4 book ai didi

clojure - Scala的zipWithIndex的Clojure等效项是什么?

转载 作者:行者123 更新时间:2023-12-02 06:54:34 26 4
gpt4 key购买 nike

Scala Seq 具有zipWithIndex方法:

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

Zips this sequence with its indices.

returns: A new sequence containing pairs consisting of all elements of this sequence paired with their index. Indices start at 0.

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


Clojure中的等效功能是什么?

最佳答案

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

user=> (map-indexed vector "foo")
([0 \f] [1 \o] [2 \o])

关于clojure - Scala的zipWithIndex的Clojure等效项是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34486710/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com